Weird gcc behaviour with function pointer types



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
.



Relevant Pages

  • Re: [PATCH] security_sk_free void return fixup
    ... Apparently it is valid C99, ... It may work in gcc, but it is invalid according to ISO C99. ... function whose return type is void. ... return.c:5: warning: `return' with a value, ...
    (Linux-Kernel)
  • Re: Want comments regarding patch
    ... Then GCC is not a "reasonably good compiler". ... void bar(struct foo *a) { ... `gcc -O3 -c test.c` will generate a classic loop rather than a repz ...
    (Linux-Kernel)
  • Re: Unexpected Result while compiling this code
    ... When I tried to compile that here (gcc ... > 4.0.2) it _did_ give me an error with a reference to function foo, ... > at the top of your code cause the code to compile cleanly. ... These are the warning messages i got when i compiled on gcc 3.2.2 ...
    (comp.lang.c)
  • Re: sizeof() a function
    ... void = malloc; ... memcpy(bar, &foo, len); ... gcc doesn't seem to honor these semantics for sizeof. ... independent by using relative jumps instead of absolute jumps. ...
    (comp.os.linux.development.system)
  • Re: Why oh why does this NOT give a compile error?
    ... void f ... I would expect at least some warning, ... With the right compiler options, gcc can be a good compiler, though what it produces is a warning about the more fundamental problem, rather than the one you're actually asking about: ...
    (comp.lang.c)