1. Home
  2. /
  3. Misra-c-cpp
  4. /
  5. MISRA C: Rule Example (Avoid Magic Numbers)

MISRA C: Rule Example (Avoid Magic Numbers) - Misra-c-cpp Typing CST Test

Loading…

MISRA C: Rule Example (Avoid Magic Numbers) — Misra-c-cpp Code

Use named constants instead of magic numbers.

/* Non-compliant */
int delay = 1000;

/* Compliant */
#define DELAY_MS 1000
int delay = DELAY_MS;

Misra-c-cpp Language Guide

MISRA C and MISRA C++ are coding standards developed to facilitate safety, reliability, and maintainability in embedded systems, especially in automotive, aerospace, and critical industries.

Primary Use Cases

  • ▸Automotive embedded software development
  • ▸Safety-critical avionics code
  • ▸Industrial control firmware
  • ▸Medical device software
  • ▸High-integrity and mission-critical systems

Notable Features

  • ▸Rule-based coding guidelines for C/C++
  • ▸Focus on safety, reliability, and maintainability
  • ▸Supports static analysis enforcement
  • ▸Includes both mandatory and advisory rules
  • ▸Covers C language and object-oriented C++ constructs

Origin & Creator

Created by the Motor Industry Software Reliability Association (MISRA) in 1998, initially for the automotive industry; later expanded to C++ and broader safety-critical domains.

Industrial Note

Extensively used in automotive ECUs, aerospace flight control software, industrial PLC firmware, and other high-integrity embedded systems.

More Misra-c-cpp Typing Exercises

MISRA C: Rule Example (Avoid Implicit Conversion)MISRA C++: Rule Example (No Dynamic Memory in Safety-Critical Code)MISRA C: Rule Example (Use of const)MISRA C: Rule Example (No goto)MISRA C: Rule Example (Initialize Variables)MISRA C++: Rule Example (Avoid Multiple Inheritance)MISRA C: Rule Example (Single Point of Exit)MISRA C++: Rule Example (No Exception Handling in Safety-Critical)MISRA C: Rule Example (Boolean Expressions)

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher