MISRA C:2012 Rule 20.13
A line whose first token is # shall be a valid preprocessing directive
Description
Rule Definition
A line whose first token is # shall be a valid preprocessing directive1
Rationale
You typically use a preprocessing directive to conditionally exclude source code until a
corresponding #else
, #elif
, or
#endif
directive is encountered. If your compiler does not
detect a preprocessing directive because it is malformed or invalid, you can end up
excluding more code than you intended.
If all preprocessing directives are syntactically valid, even in excluded code, this unintended code exclusion cannot happen.
Additional Message in Report
Directive is not syntactically meaningful.
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 |
1 All MISRA coding rules and directives are © Copyright The MISRA Consortium Limited 2021.
The MISRA coding standards referenced in the Polyspace® Bug Finder™ documentation are from the following MISRA standards:
MISRA C:2004
MISRA C:2012
MISRA C:2023
MISRA C++:2008
MISRA C++:2023
MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.