Ken said:
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?)