Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rule 4-10-2 NULL is not a c++ standard
#1
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.
<t></t>
Reply
#2
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.
Posted by and on behalf of
the MISRA C++ Working Group
Reply
#3
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.
<t></t>
Reply
#4
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).
<t></t>
Reply
#5
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;
Posted by and on behalf of
the MISRA C++ Working Group
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)