mike.h on Sun, 8 Dec 2002 23:40:10 -0500 |
Jeff, Using a forward declaration, this compiled & ran without error or warning: struct bar; /* forward declaration */ int foo(struct bar *b); typedef struct bar { int a; } Bar; int main(){ struct bar *b; Bar *b2; foo(b); foo(b2); return 0; } int foo(struct bar *b){ return 0; } On Sun, 2002-12-08 at 16:59, Jeff Abrahamson wrote: > 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; > > foo(Bar *b) > { > return 0; > } > > jeff@diderot:scratch $ gcc -Wall -c struct2.c > struct2.c:1: warning: `struct bar' declared inside parameter list > struct2.c:1: warning: its scope is only this definition or declaration, which is probably not what you want. > struct2.c:8: warning: return-type defaults to `int' > struct2.c:8: conflicting types for `foo' > struct2.c:1: previous declaration of `foo' > jeff@diderot:scratch $ > > At line 1, the size of the structure is not needed, so the declaration > should be ok by my reading of K&R. Then at line 8, Bar is a synonym > for struct bar, so it should be ok, again as per my understanding of > K&R (by which I mean the ANSI C version, of course). > > jeff@diderot:scratch $ gcc -v > Reading specs from /usr/lib/gcc-lib/i386-linux/2.95.4/specs > gcc version 2.95.4 20011002 (Debian prerelease) > jeff@diderot:scratch $ > > -- > Jeff > > Jeff Abrahamson <http://www.purple.com/jeff/> > GPG fingerprint: 1A1A BA95 D082 A558 A276 63C6 16BF 8C4C 0D1D AE4B _________________________________________________________________________ Philadelphia Linux Users Group -- http://www.phillylinux.org Announcements - http://lists.netisland.net/mailman/listinfo/plug-announce General Discussion -- http://lists.netisland.net/mailman/listinfo/plug
|
|