[comp.lang.c] Is this a GCC bug ?

dan@charyb.COM (Dan Mick) (02/01/90)

In article <7948@shlump.nac.dec.com> nadkarni@ashok.dec.com writes:
|
|Is this a bug in the Gnu CC compiler or is it illegal C ?
|
|------------------------------
|typedef void foo(struct urb *p);
|
|
|struct urb 
|{
|    int i;
|} ;
|-------------------------------
|gcc -S bug.c
|bug.c:1: warning: `struct urb' declared inside parameter list
|bug.c:1: warning: such a name is accessible only within its parameter list,
|bug.c:1: warning: which is probably not what you want.
|
|Thanks,
|
|/Ashok Nadkarni
|Digital Equipment Corp.


It's possible I'm being incredibly dense again, but it seems to me that you
need to define struct urb before you get to the typedef in order to 
avoid the warning; all it's telling you is that it doesn't know about
struct urb until it sees the parameter list.  

True, the parm p is a struct urb * and not struct urb, so it doesn't need 
the size info, but until you define struct urb later, it's warning you that 
you can't use struct urb in any other context.  

The program still works, right?

karl@haddock.ima.isc.com (Karl Heuer) (02/02/90)

In article <355@charyb.COM> dan@charyb.UUCP (Dan Mick) writes:
>In article <7948@shlump.nac.dec.com> nadkarni@ashok.dec.com writes:
>|Is this a bug in the Gnu CC compiler or is it illegal C ?
>|	typedef void foo(struct urb *p);
>|	struct urb { int i; } ;
>|bug.c:1: warning: `struct urb' declared inside parameter list
>|bug.c:1: warning: such a name is accessible only within its parameter list,
>|bug.c:1: warning: which is probably not what you want.

The problem is that you have two declarations of `struct urb', and they have
nonintersecting scopes--so they actually declare two different types.  You
should either put the typedef before the prototype, or else force a common
scope by adding the empty declaration `struct urb;' at the top.

>[partially correct analysis omitted]
>The program still works, right?

Since it can be derived that `all struct pointers smell the same', the program
will probably work.  But when you try to invoke foo() with an argument of type
`struct_urb_2_pointer', the prototype requires the compiler to convert it to a
`struct_urb_1_pointer', which may yield another warning.

Karl W. Z. Heuer (karl@ima.ima.isc.com or harvard!ima!karl), The Walking Lint