Page 1 of 1

Rule 4-10-2 NULL is not a c++ standard

Posted: Fri Feb 07, 2014 7:34 am
by minhyuk
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

Posted: Mon Oct 05, 2015 2:47 pm
by misra cpp
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

Posted: Fri Jan 06, 2017 6:07 am
by minhyuk
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)
C.2.2.3 Macro NULL [diff.null]
1 The macro NULL, defined in any of <clocale>, <cstddef>, <cstdio>, <cstdlib>, <cstring>,
<ctime>, or <cwchar>, 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

Posted: Mon Jan 09, 2017 6:30 am
by dg1980
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)
C.2.2.3 Macro NULL [diff.null]
1 The macro NULL, defined in any of <clocale>, <cstddef>, <cstdio>, <cstdlib>, <cstring>,
<ctime>, or <cwchar>, 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

Posted: Tue Jan 24, 2017 10:13 am
by misra cpp
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;