I have this piece of code in C:
void f(void *x) {
printf(">>> %p\n", x);
}
int main() {
f NULL;
return 0;
}
I think is for the definition of NULL, but I'd like an explanation to clarify my doubt.
I have this piece of code in C:
void f(void *x) {
printf(">>> %p\n", x);
}
int main() {
f NULL;
return 0;
}
I think is for the definition of NULL, but I'd like an explanation to clarify my doubt.
If NULL
is defined as ((void *)0)
or (0)
, then this expands to f ((void *)0)
or f (0)
, which are proper function calls. The code errors out for anything non-parenthesized during compilation.
In C NULL
is often defined as follows:
#if !defined(NULL)
#define NULL ((void*)0)
#endif
If this is the case then NULL
is just a special pointer, and you example works.