Rationale for 11.9 -- NULL constant

Moderators: misra-c, david ward

Post Reply
Posts: 1
Joined: Tue Jul 17, 2012 9:50 am
Company: Amantys

Rationale for 11.9 -- NULL constant

Post by stephen.parker » Mon Sep 09, 2013 11:45 am

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.


Posts: 571
Joined: Thu Jan 05, 2006 1:11 pm

Re: Rationale for 11.9 -- NULL constant

Post by misra-c » Thu Sep 12, 2013 10:22 am

The standard (ISO 9899:1999 defines a null pointer constant:
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++
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “8.11 Pointer type conversions”