MISRA-C:2023에서 변화된 규칙과 사용자들이 유의해야 할 점에 대해 IAR SYSTEMS JAPAN의 Hiroki Akaboshi FAE가 이야기 한다.
“MISRA-C C11·C18 New Syntax Must Be Used”
Risk of subtle bugs and undefined behavior when ignoring MISRA
Static analysis tools help catch rule violations before they become bugs
■ MISRA-C:2023: Strengthening Safety Standards for C Developers MISRA-C has evolved again. If you work on safety-critical systems in C, you’re likely familiar with MISRA-C:2012, but MISRA-C:2023 brings some important changes you’ll want to know about.
■ Why MISRA-C is evolving
MISRA-C is a globally recognized set of coding guidelines designed to make C code safer, more reliable, and easier to maintain.
Starting with MISRA-C:1998, this guideline has evolved to meet the needs of modern development. So why does it continue to evolve?
The simple answer is that C is evolving too. The MISRA-C guidelines are adjusted to address new standards for the C language as the programming environment evolves.
In 2012, the major standards were C90 and C99, which had been established in 1990 and 1999 respectively.
Since then, new standards such as C11 (2011) and C18 (2018) have emerged, providing powerful features such as multithreading and generic expressions.
These additions, especially in C11, present new challenges in writing safe and reliable code, especially when dealing with concurrency and shared data.
MISRA-C:2012 could no longer fully cover the latest features of these new standards. MISRA-C:2023 appeared, narrowing the scope to four versions of the C language: C90, C99, C11, and C18. Although C18 provides minimal functional changes compared to C11, this update was essential to keep the guidelines in sync with the evolving language and its features.
■ What's new in MISRA-C:2023 One of the key features of MISRA-C:2023 is support for rules that come with new language constructs.
For example, consider the atomic types introduced in C11, which are essential for safe multithreaded applications.
These rules help us manage shared variables safely across multiple threads.
However, it also poses potential risks if misused, so MISRA-C:2023 includes the following updated rules:
※ Rule 9.7 Atomic objects must be properly initialized before accessing them.
※ Rule 12.6 Structure and union members of atomic objects must not be accessed directly.
The following example shows the use of the atomic type modifier introduced in C11, but does not conform to the previously mentioned rules.
▲Violation of atomic variable rules
■ Why you should care about these updates If your development involves multithreading or multicore systems, you should be careful. As the industry embraces this programming paradigm, it will be essential to take advantage of the new syntax provided in C11 and C18. These features are very powerful, but of course they also come with a liability. If you don't follow the latest MISRA guidelines, you risk introducing subtle bugs or undefined behavior into your code. These problems can go unnoticed.
■ Static analysis tool for structures Of course, knowing the rules is only half the battle. Ensuring that your code complies with them is equally important. Static analysis tools are invaluable tools that help catch rule violations before they turn into costly bugs.
As a leader in embedded development, IAR has been quick to adopt MISRA-C:2023.
The IAR C-STAT add-on for IAR Embedded Workbench, introduced in version 9.60.2, now lets you verify your code against the latest guidelines to ensure your projects are compliant.
▲Added C-STAT tool (related to MISRA-C:2023)
■ MISRA-C: Recommended for project application in 2023 MISRA-C:2023 represents a major advance for C programmers working in safety-critical areas. The updated guidelines cover the latest features of the C language to help you write functional, safe, stable, and future-proof code.
If you are already using MISRA-C:2012, now is the perfect time to upgrade and take advantage of the latest standard for your embedded projects.
Adopting new guidelines and tools like IAR's C-STAT can help solve next-generation embedded development challenges.
More information about C-STAT can be found below.
https://www.iar.com/products/c-stat/ ※ Author
Hiroki Akaboshi / FAE / IAR SYSTEMS JAPAN