MISRA C++ compliant definition of NULL

Moderators: david ward, misra cpp

Post Reply
jorgen_h_karlsson
Posts: 1
Joined: Tue Aug 04, 2009 2:04 pm
Company: ABB Cewe-Control

MISRA C++ compliant definition of NULL

Post by jorgen_h_karlsson » Wed Aug 05, 2009 3:17 pm

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: Select all

const int NULL = 0; // Compliant with rule 3-1-1?
If so, what is a compliant definition of NULL then?

Best regards,
/J

misra cpp
Posts: 148
Joined: Mon Jun 02, 2008 1:55 pm
Company: MISRA

Re: MISRA C++ compliant definition of NULL

Post by misra cpp » Tue Oct 11, 2016 10:23 am

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."
Posted by and on behalf of
the MISRA C++ Working Group

Post Reply

Return to “6.3 Basic concepts (C++)”