NULL v. zero
Posted Jul 15, 2004 13:34 UTC (Thu) by
elanthis (subscriber, #6227)
In reply to:
NULL v. zero by ikm
Parent article:
NULL v. zero
The C compiler and standards will accept a lot of things that are garbage, in all honesty. Just because a NULL pointer is just 0 is really nothing more than an implementation detail. It's also an artifact of C's weak type checking, which is one argument people often use in favor of C++, Java, C#, etc.
A code checker like Sparse will often enforce a stricter dialect than standard C, which is a good thing, because then it will find errors that the normal C compiler wouldn't pick up. Correct type checking is one such error.
It also does improve readability. If you are skimming through some code, and see:
if (var == 0) { ... }
You are likely to assume var is an integer, no? However, if you see:
if (var == NULL) { ... }
You are likely to assume var is a pointer, yes? Using the appropriate type makes the code easier to read and understand.
(
Log in to post comments)