?
=?ISO-8859-15?Q?Juli=E1n?= Albo
SuperKoko said:There are several good reasons.
The best one : It is more human-friendly... You know the intent of the
programmer (assuming that the programmer uses NULL in pointer contexts
only).
I think that NULL is human-unfriendly precisely because that: I have seen a
lot of code where people mixes NULL used as pointer and used as char (I
suppose they suffer a confusion with the ascii NUL char name). Some people
even write things like:
char * txt;
(...)
if (txt == NULL || txt [0] == NULL)
I would like to say that the fact that NULL is not type safe in C++
doesn't mean that it must not be used... Even if the compiler doesn't
make any difference between NULL and 0, programmers do.
The point of type safety is that the compiler can help to avoid some
mistakes. As my previous paragraph shows, NULL does not prevent some
obvious mistakes. It even help create new ones because of the name
confusion with NUL.