Dir 4.10: Is a different form of the include guard considered a violation of the directive? - Printable Version +- MISRA Discussion Forums (https://forum.misra.org.uk) +-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4) +--- Forum: MISRA C:2012 and MISRA C:2023 guidelines (https://forum.misra.org.uk/forumdisplay.php?fid=21) +---- Forum: 7.4 Code design (https://forum.misra.org.uk/forumdisplay.php?fid=181) +---- Thread: Dir 4.10: Is a different form of the include guard considered a violation of the directive? (/showthread.php?tid=1411) |
Dir 4.10: Is a different form of the include guard considered a violation of the directive? - GerlindeKettl - 29-03-2018 The example of Directive 4.10 "Precautions shall be taken in order to prevent the contents of a header file being included more than once" says that in order to facilitate checking, the contents of the header should be protected from being included more than once using one of the following two forms: Code: #if !defined ( identifier ) Code: #if ( !defined identifier ) Re: Dir 4.10: Is a different form of the include guard considered a violation of the directive? - misra-c - 24-04-2018 #if (!defined identifier) does not violate directive 4.10. Dir 4.10 is a directive which means a full description is not provided ( see Section 6.1) Static analysis tools may assist in checking compliance of directives, but different tools may place different interpretations on what constitutes a non-compliance. The purpose of the Directive is to prevent multiple inclusion of an Include file, and while the examples provided are informative only, any other form of Include Guard is compliant. However, it is accepted that the two forms shown as examples that are most commonly checked by static analysis tools. Therefore the user is encouraged to use those forms where possible. |