From clc-wiki
Description
The NULL macro is defined by many headers to expand to an implementation-defined null pointer constant. The advantage over using literal 0 is the warnings produced by current compilers on most forms of improper use. It might simply be defined as:
#define NULL 0
Definition
Defined in <stddef.h>, <locale.h>, <stdio.h>, <stdlib.h>, <string.h>, <time.h>.
In standard C, this can be implemented as:
#if !defined(NULL) #define NULL ((void*)0) #endif
Code snippet, portable C90; public domain; past reviewers: none; current reviews: none
Interpretation wrangling
Some people claim that by a strict reading of the Standard, after parenthesising the expression (void *)0
, it's no longer a null pointer constant, even though the parentheses are simultaneously required by the Standard to protect the macro expansion. No one seems to dispute that it's the Standard's intention that ((void *)0)
is a valid definition of NULL, nor that any other reading is sensible.
References
- The C Standard: 7.17#3, 17.19.1#3, 7.20#3, 7.21.1#1, 7.23.1#2, 7.24.1#3 (N1124 numbering)
- FAQ section 5 Null Pointers