Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!mcsun!ukc!inmos!conor@lion.inmos.co.uk From: conor@lion.inmos.co.uk (Conor O'Neill) Newsgroups: comp.std.c Subject: gcc and NULL function pointers. Message-ID: <16386@ganymede.inmos.co.uk> Date: 3 Jun 91 10:39:28 GMT Sender: news@inmos.co.uk Reply-To: conor@inmos.co.uk () Organization: INMOS Limited, Bristol, UK. Lines: 38 Consider the following function: void f(void) { void (*ptr)(void); /* pointer to void function returning void */ ptr = 0; /* 1 */ ptr = (void *)0; /* 2 */ ptr = (void (*)(void))0; /* 3 */ ptr = (void (*)(void))((void *)0); /* 4 */ } When compiled with gcc version 1.39, with -ansi -pedantic, it reports a warning on the line marked /* 2 */: c.c:6: warning: assignment between incompatible pointer types (Note, without -pedantic gcc is silent) On our system, NULL is #defined in a header file to be ((void *)0), thus gcc will give a warning when attempting to set a function pointer to NULL. ANSI standard states (section 3.3.16.1) that a constraint on simple assignment is that (...) "the left operand is a pointer and the right is a null pointer constant". The index points me to section 3.2.2.3 for a definition: "An integral constant expression with the value 0, or such an expression cast to type void *, is called a null pointer constant. 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" Thus, I claim that /* 2 */ should be converted by the compiler to /* 4 */ and thus should not create a warning. Hence gcc is incorrect in this point. --- Conor O'Neill, Software Group, INMOS Ltd., UK. UK: conor@inmos.co.uk US: conor@inmos.com "It's state-of-the-art" "But it doesn't work!" "That is the state-of-the-art".