MISRA Discussion Forums
Rules 16-2-3 - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C++ (https://forum.misra.org.uk/forumdisplay.php?fid=18)
+--- Forum: MISRA C++:2008 rules (https://forum.misra.org.uk/forumdisplay.php?fid=19)
+---- Forum: 6.16 Preprocessing directives (C++) (https://forum.misra.org.uk/forumdisplay.php?fid=144)
+---- Thread: Rules 16-2-3 (/showthread.php?tid=1466)



Rules 16-2-3 - nishiyama - 05-02-2019

Rules 16-2-3 Rationale has the following description.

If this multiple inclusion leads to multiple or conflicting definitions,
then this can result in undefined or erroneous behaviour.

I understood that it would be a multiple definition.

However, I do not understand the case of conflicting definition.
What kind of cases are there?


Re: Rules 16-2-3 - dg1980 - 08-02-2019

Hi,

i believe if you follow rule 3-2-3 strictly it is impossible to have conflicting definitions (because linker does not check types in different translation units).
If you need more background google "C traps and pitfalls" by Koenig and check chapter 3.1.


Re: Rules 16-2-3 - misra cpp - 10-04-2019

We agree with dg1980. Strict adherence to 3-2-3 ensures conflicting definitions will not occur. Requiring include guards ensures that, for headers at least, 3-2-3 will be observed