MISRA Discussion Forums
Rationale for 11.9 -- NULL constant - 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: 8.11 Pointer type conversions (https://forum.misra.org.uk/forumdisplay.php?fid=166)
+---- Thread: Rationale for 11.9 -- NULL constant (/showthread.php?tid=981)



Rationale for 11.9 -- NULL constant - stephen.parker - 09-09-2013

Can anyone explain what the rationale is for this rule? I could think of several arguments for why you shouldn't use NULL, and should prefer a plain 0 (as is generally preferred in C++). This feels like a stylistic issue.

Thanks,
stephen


Re: Rationale for 11.9 -- NULL constant - misra-c - 12-09-2013

The standard (ISO 9899:1999 6.3.2.3) defines a null pointer constant:

Quote:An integral constant expression with the value 0 , or such an expression cast to type void *, is called a null pointer constant.
This means, for example that it is legitimate in the C language to compare a pointer expression with any form of integer constant expression including for example '\0' or any enum constant of value 0. For this reason it is advisable to use NULL wherever a null pointer constant is intended.

The semantics are subtly different in C++