Blog | IAR

MISRA-C:2023 – Elevating safety standards for C developers

Written by IAR Systems | Sep 24, 2024 11:14:01 AM

Why is MISRA-C evolving?

MISRA-C is a globally recognized set of coding guidelines designed to make C code safer, more reliable, and easier to maintain. From its origins in MISRA-C:1998, the guidelines have evolved to meet the demands of modern development. So, why this continuous evolution?

The simple answer: C is evolving, too! MISRA-C guidelines adapt to cover new standards in the C language, which change as the programming landscape shifts. In 2012, the dominant standards were C90 and C99, established in 1990 and 1999, respectively. Since then, newer standards like C11 (2011) and C18 (2018) have emerged, bringing powerful features like multithreading and generic expressions. These additions, especially in C11, introduce new challenges in writing safe, reliable code—particularly when dealing with concurrency and shared data.

MISRA-C:2012 (without amendments and addendums) could no longer fully cover the modern features of these newer standards. Enter MISRA-C:2023, which reduces the scope to just four C language versions: C90, C99, C11, and C18. Though C18 brings minimal functional changes compared to C11, this update was essential to ensure the guidelines keep up with the evolving language and its capabilities.

What's new in MISRA-C:2023?

One key feature of MISRA-C:2023 is its support for newer language syntax and the rules that come with it. For example, consider the atomic types introduced in C11, essential for safe multithreaded applications. These help you safely manage shared variables across different threads. However, they also introduce potential risks if misused, which is why MISRA-C:2023 includes updated rules like:

  • Rule 9.7 Atomic objects shall be appropriately initialized before being accessed
  • Rule 12.6 Structure and union members of atomic objects shall not be directly accessed

The following example demonstrates the use of the atomic type modifier, introduced in C11. However, it does not comply with the previously mentioned rules.

Why you should care about these updates

If your development involves multithreading or multi-core systems, you need to pay attention. As the industry embraces these programming paradigms, leveraging the new syntax provided by C11 and C18 will become essential. But with great power comes great responsibility! If you don't follow the latest MISRA guidelines, you risk introducing subtle bugs or undefined behavior into your code—problems that could slip through the cracks.

Static analysis tools to the rescue

Of course, knowing the rules is only half the battle; ensuring your code adheres to them is just as critical. This is where static analysis tools prove invaluable, helping you catch rule violations before they turn into costly bugs. As a leader in embedded development, IAR has swiftly adopted MISRA-C:2023. With the IAR C-STAT add-on for IAR Embedded Workbench, introduced in version 9.60.2, you can now verify your code against the latest guidelines, ensuring your project remains compliant.

 

Summary

MISRA-C:2023 represents a significant step forward for C programmers working in safety-critical fields. The updated guidelines address modern features of the C language, helping you write code that is not only functional but also safe, reliable, and future-proof. If you already use MISRA-C:2012, now is the perfect time to upgrade and ensure you're leveraging the latest standards for your embedded projects.

Adopting these new guidelines and tools like C-STAT from IAR will enable you to tackle the next generation of embedded development challenges.