Why is this form true in C?
I have this piece of code in C:
void f(void *x) { printf(">>> %p\n", x); } int main() { f NULL; return 0; } I think for the definition of NULL, but I would like to explain to clarify my doubts.
+8
Kyrol
source share2 answers
If NULL defined as ((void *)0) or (0) , then it expands to f ((void *)0) or f (0) , which are valid function calls. Code errors for anything not enclosed in parentheses at compile time.
+9
user529758
source shareIn C, NULL often defined as follows:
#if !defined(NULL) #define NULL ((void*)0) #endif If so, then NULL is just a special pointer, and you, for example, work.
+2
jbr
source share