MISRA C:2012 Rule 20.14
All #else, #elif and #endif preprocessor directives shall reside in the same file as the #if, #ifdef or #ifndef directive to which they are related
Description
Rule Definition
All #else, #elif and #endif preprocessor directives shall reside in the same file as the #if, #ifdef or #ifndef directive to which they are related.
Rationale
When conditional compilation directives include or exclude blocks
of code and are spread over multiple files, confusion arises. If you
terminate an #if
directive within the same file,
you reduce the visual complexity of the code and the chances of an
error.
If you terminate #if
directives within the
same file, you can use #if
directives in included
files
Additional Message in Report
'#else' not within a conditional.
'#elseif' not within a conditional.
'#endif' not within a conditional.
Unterminated conditional directive.
Troubleshooting
If you expect a rule violation but do not see it, refer to Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Check Information
Group: Preprocessing Directives |
Category: Required |
AGC Category: Required |