MISRA Discussion Forums
MISRA C++ compliant definition of NULL - 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.3 Basic concepts (C++) (https://forum.misra.org.uk/forumdisplay.php?fid=132)
+---- Thread: MISRA C++ compliant definition of NULL (/showthread.php?tid=673)



MISRA C++ compliant definition of NULL - jorgen_h_karlsson - 05-08-2009

According to the rationale of required rule 3-1-1 a header file should not contain or produce definitions of objects or functions.

Does this mean that the following definition of the null-pointer-constant NULL is non-compliant?
Code:
const int NULL = 0; // Compliant with rule 3-1-1?
If so, what is a compliant definition of NULL then?

Best regards,
/J


Re: MISRA C++ compliant definition of NULL - misra cpp - 11-10-2016

The ODR does not apply to const declarations as they have internal linkage, not external (the definition of the ODR explicitly says it only applies to objects with external linkage). So the examples quoted are compliant.

The first paragraph of the rationale will be replace with the following in "MISRA C++:2008 Technical Corrigendum 1":
"It shall be possible to include a header file into multiple translation units without violating the One Definition Rule. See section 6.3.2 for an explanation of the ODR."