MISRA C++:2023 Rule 19.0.4
#undef
should only be used for macros defined previously in the
same file
Since R2024b
Description
Rule Definition
#undef
should only be used for macros defined previously in
the same file.
Rationale
Using #undef
in the same file as the macro definition limits the
scope of macros, minimizing conflicts and unintentional consequences due to use of
macros defined in other files. Following this guideline also promotes better code
organization by defining and undefining each macro in a single file, making code easier
to read and maintain.
Polyspace Implementation
Polyspace® reports a rule violation whenever a macro is undefined in a file where it is not also defined.
Troubleshooting
If you expect a rule violation but Polyspace does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Preprocessing Directives |
Category: Advisory |
Version History
Introduced in R2024b