Johs32 said:
If I have a pointer and initialize it to NULL does it have the same effect
if I initialize it to 0 instead, no matter what kind of pointer it is?
Yes.
However, speaking of 0 versus NULL, there is a common kind of error that
surfaces when using 0 but not NULL on many systems: in order to pass a null
pointer to a variadic function (like printf()) you must explicitly cast the
null pointer constant to a pointer type. E.g.:
WRONG:
printf("%p", 0);
Here 0 is passed as an integer, not a pointer. This will fail on systems
where pointers and integers are not the same size and on systems where the
null pointer is not all-bits-zero.
STILL WRONG:
printf("%p", NULL);
This is still wrong because NULL can legally be defined as 0, triggering the
same problem. However, many systems define NULL as ((void*) 0), which
happens to work. Stress "happens to".
RIGHT:
printf("%p", (void*) 0);
printf("%p", (void*) NULL);
Variadic functions always have this problem because the compiler can't check
(or rather isn't required to check) the argument types. The same applies to
a call to a function which doesn't have a prototype in scope (just don't do
that).
For the full story (and a whole lot more), see chapter 5 of the FAQ:
http://www.c-faq.com/null/index.html.
S.