NULL v. zero
Linus responds that programmers who interchange NULL and zero are confused about the types they are using and are putting that confusion into the kernel. In his desire to enable the compiler (and other compile-time checkers) to find errors, he wants to separate the integer and pointer types as completely as possible. NULL is a pointer, while 0 can never be.
char * p = 0; /* IS WRONG! DAMMIT! */ int i = NULL; /* THIS IS WRONG TOO! */
and anybody who writes code like the above either needs to get out of the kernel, or needs to get transported to the 21st century.
One might conclude from this statement that Linus is pretty well convinced
that the current course of action is correct. He also states that, without exception, changing zero
to NULL has resulted in better, more readable code. So use of
NULL seems to have become part of the official kernel coding
style, even if the CodingStyle document is
still silent on the matter.
| Index entries for this article | |
|---|---|
| Kernel | Coding style |
| Kernel | NULL and zero |
