Weird gcc behaviour with function pointer types

greg greg at cosc.canterbury.ac.nz
Thu Mar 29 09:05:12 EDT 2007


In my quest to eliminate C compiler warnings from
Pyrex output, I've discovered some utterly bizarre
behaviour from gcc 3.3.

The following code:

   void g(struct foo *x) {
   }

   void f(void) {
     void (*h)(struct foo *);
     h = g;
   }

produces the following warning:

   blarg.c: In function `f':
   blarg.c:6: warning: assignment from incompatible pointer type

However, adding the following line at the top:

   typedef struct foo Foo;

makes the warning go away. The mere *presence* of
the typedef is all that's needed -- it doesn't even
have to be used.

This looks like a bug in gcc to me -- what do people
think?

--
Greg



More information about the Python-list mailing list