----- Original Message ----- From: "Josh Wilmes" <[EMAIL PROTECTED]> To: "Brian Lee Ray" <[EMAIL PROTECTED]> Cc: "Nicholas Clark" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Saturday, February 23, 2002 12:08 PM Subject: Re: [PATCH] Bowing to necessity (was Re: [PATCH]Macro bulletproofing )
> At 6:57 on 02/23/2002 CST, Brian Lee Ray <[EMAIL PROTECTED]> wrote: > > 2:f=0; > > f=NULL; > > f=(void*)0; /*all valid: assignment of a null pointer > > *constant to a function pointer*/ > > It doesn't accept that last one. > > "test2.c", line 12: Error: > [ISO 6.3.4]: Can't convert function pointer 'void *' to non-function pointer 'void >( * ) ( void )'. > [ISO 6.3.16]: Can't perform this conversion by assignment. that's what I take issue with. An integral constant expression with the value 0, or such an expression cast to type void *, is called a null pointer constant. this is a null pointer constant: (void*)0 If a null pointer constant is assigned to or compared for equality to a pointer, the constant is converted to a pointer of that type. assigned to a pointer: f=(void *)0; compared for equality to a pointer: f==(void*)0; It doesn't say "to a pointer of compatible type". after all, if that were the case, it couldn't convert the integer zero to a pointer, could it? Just for the sake of curiosity, here's what I get with gcc -ansi -pedantic -Wall -W -O: #include <stdio.h> #include <stdlib.h> int main(void) { void *v=NULL; typedef void(*fptr)(void); fptr f; f=v; /*invalid: assignment of a void pointer to a function pointer*/ test2.c:10: warning: ANSI forbids assignment between function pointer and `void *' f=0;f=NULL;f=(void*)0; /*all valid: assignment of a null pointer *constant to a function pointer*/ v=f; /*invalid: assignment of a function pointer to a void pointer*/ test2.c:13: warning: ANSI forbids assignment between function pointer and `void *' f==0;/*valid:comparison of a function pointer to a null pointer constant*/ test2.c:14: warning: statement with no effect f==(void*)0;/*valid:comparison of a function pointer to a null pointer constant*/ test2.c:15: warning: statement with no effect f==NULL;/*valid:comparison of a function pointer to a null pointer constant*/ test2.c:16: warning: statement with no effect f==(fptr)v;/*must compile, however, unless both f and v are null pointers, test2.c:17: warning: statement with no effect *the result is undefined. I would expect a warning for this, as *it is a really stupid thing to do. after all, if you know that *f and v are both null pointers, the result will hardly be surprising*/ return 0; } brian.