Michael C. Toren on Sun, 8 Dec 2002 17:58:11 -0500 |
> I wonder if someone can help me see what I'm missing. > > The following code snippet yields a warning and an error. I don't > think it should. Am I confused, or is gcc? > > int foo(struct bar *b); > > typedef struct bar { > int a; > } Bar; > At line 1, the size of the structure is not needed, so the declaration > should be ok by my reading of K&R. It looks to me like the root problem is referencing a structure before you define it, and that the error messages regarding the typedef simply stems from this problem. Reducing your example to simply: struct bar { int a; }; int foo(struct bar *b); works fine, however: int foo(struct bar *b); struct bar { int a; }; does not. I don't have a copy of K&R handy at the moment, and I don't know offhand if the second example is valid C, but my guess would be that it isn't. Would it be possible in the code you're working on to list the structure definitions first, as a workaround? -mct
|
|