cechew@sol1.cs.monash.edu.au (Earl Chew) (02/27/91)
The standard states that 0 and (void *) 0 are `null pointers'. Does this mean that they are equivalent in all contexts? Specifically: int (*f)(void) = 0; My understanding is that this is permissible. int (*f)(void) = (void *) 0; I am unsure whether this is permissible. Earl -- Earl Chew, Dept of Computer Science, Monash University, Australia 3168 EMAIL: cechew@bruce.cs.monash.edu.au PHONE: 03 5655778 FAX: 03 5655146 ----------------------------------------------------------------------
torek@elf.ee.lbl.gov (Chris Torek) (02/27/91)
In article <cechew.667604378@sol1> cechew@sol1.cs.monash.edu.au (Earl Chew) writes: >The standard states that 0 and (void *) 0 are `null pointers'. More precisely, they are `null pointer constants'. While (void *)0 is a null pointer, 0 is not a null pointer; it is merely a null pointer constant (as well as the integer constant 0). >Does this mean that they are equivalent in all contexts? No; but: >Specifically: > int (*f)(void) = 0; >My understanding is that this is permissible. Yes. > int (*f)(void) = (void *) 0; >I am unsure whether this is permissible. It is. The integral constant zero is peculiar in that it has two meanings: integer 0, or generic nil pointer constant. (void *)0 is also peculiar: it is both a generic nil pointer constant and a specific nil pointer (nil pointer to void). The difference between the two manifests in several contexts, including: printf("%d\n", (int)sizeof(0)); vs printf("%d\n", (int)sizeof((void *)0)); or, given extern void f(); /* no prototype! */ f(0); vs f((void *)0); Each statement in each pair will do something different from the other in its pair, at least on some systems. -- In-Real-Life: Chris Torek, Lawrence Berkeley Lab EE div (+1 415 486 5427) Berkeley, CA Domain: torek@ee.lbl.gov