Re: NULL macro vs. 0 as null pointer?

From: Julie (julie_at_nospam.com)
Date: 07/23/04


Date: Fri, 23 Jul 2004 09:01:28 -0700

Ken wrote:
>
> Hi all. When referring to a null pointer constant in C++, is there
> any reason to prefer using 0 over a macro called NULL that is defined
> to be 0?

There is no right answer, and from an 'enforcement' standpoint, you will only
cause problems.

If you are simply asking for yourself, you will need to decide what suits you
best.

The general thoughts are:

 - NULL can make it more clear in the code that you are expecting and dealing
with pointers, but NULL is not part of the language proper, but part of the
library (meaning that you must include a library before it is defined).

 - 0 requires no support library (i.e. it is part of the language proper), but
it can lead some loss of code clarity when dealing w/ pointers (specifically
integer pointers, is the intent to compare the pointer or the destination of
the pointer?)



Relevant Pages

  • Re: better understanding references
    ... > accepts the address of what it is passed as oppose to the value. ... > that we are dealing with the value but the address of the value of what is ... > dont have to mess around with pointers. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Java and Windows GUI Integration
    ... Mustafa K. Isik wrote: ... I'm set out to look into and can provide me with pointers to material ... dealing with similar issues. ...
    (comp.lang.java.gui)
  • Re: better understanding references
    ... accepts the address of what it is passed as oppose to the value. ... that we are dealing with the value but the address of the value of what is ... dont have to mess around with pointers. ... some type or meaning except used with binary or logical operators. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: huge pointer
    ... > malikguna@yahoo.com writes: ... > Unless the book is dealing with computing history, huge pointers ... fixes many of the shortcomings of Windows 98 SE". ...
    (comp.lang.c)