MISRA Discussion Forums
Rule 4-10-2 NULL is not a c++ standard - 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.4 Standard conversions (C++) (https://forum.misra.org.uk/forumdisplay.php?fid=133)
+---- Thread: Rule 4-10-2 NULL is not a c++ standard (/showthread.php?tid=1026)



Rule 4-10-2 NULL is not a c++ standard - minhyuk - 07-02-2014

In C++ Standard, There are not exist NULL(its C standard).
So, Programmer should to know about this and Use constant 0 instead of NULL macro.


Re: Rule 4-10-2 NULL is not a c++ standard - misra cpp - 05-10-2015

NULL is defined in C++ (see 4.10 of the Language Reference Manual).

Note that 4-10-2 does not ban the use of the token "NULL", but it does prohibit the use of literal "0" as a null pointer.


Re: Rule 4-10-2 NULL is not a c++ standard - minhyuk - 06-01-2017

misra cpp Wrote:NULL is defined in C++ (see 4.10 of the Language Reference Manual).

Note that 4-10-2 does not ban the use of the token "NULL", but it does prohibit the use of literal "0" as a null pointer.

according to ISO-IEC-14882(2003)
Quote:C.2.2.3 Macro NULL [diff.null]
1 The macro NULL, defined in any of , , , , ,
, or , is an implementation-defined C + + null pointer constant in this International
Standard (18.1).
According to 4.10 of the C++ standard, a null pointer constant is defined as an integer type of rvalue that is zero.
In order to use NULL, special headers must be included in the code, and 0 is defined as a null pointer constant in the C ++ standard, so I think it is more correct to use 0 rather than NULL.


Re: Rule 4-10-2 NULL is not a c++ standard - dg1980 - 09-01-2017

minhyuk Wrote:
misra cpp Wrote:NULL is defined in C++ (see 4.10 of the Language Reference Manual).

Note that 4-10-2 does not ban the use of the token "NULL", but it does prohibit the use of literal "0" as a null pointer.

according to ISO-IEC-14882(2003)
Quote:C.2.2.3 Macro NULL [diff.null]
1 The macro NULL, defined in any of , , , , ,
, or , is an implementation-defined C + + null pointer constant in this International
Standard (18.1).
According to 4.10 of the C++ standard, a null pointer constant is defined as an integer type of rvalue that is zero.
In order to use NULL, special headers must be included in the code, and 0 is defined as a null pointer constant in the C ++ standard, so I think it is more correct to use 0 rather than NULL.
If you don't want to include those headers just use a deviation permit (something like NULL is obsolete because C++11 has the far safer nulllptr keyword).


Re: Rule 4-10-2 NULL is not a c++ standard - misra cpp - 24-01-2017

Whilst agreeing with dg1980, an alternative approach if you know you do not want to include any of the C headers that include the NULL definition is to add the #define NULL 0 declaration yourself (making any required deviations necessary for use of #define other than as a guard)

The aim is to try and make it clear to the programmer (and particularly any subsequent maintainers) the difference between a value that is a pointer and an integer, hence not allowing pointer = 0;