Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!rpi!uupsi!cmcl2!adm!smoke!gwyn From: gwyn@smoke.brl.mil (Doug Gwyn) Newsgroups: comp.lang.c Subject: Re: Undefined structures Message-ID: <15069@smoke.brl.mil> Date: 4 Feb 91 20:27:45 GMT References: <442@newmedia.UUCP> Organization: U.S. Army Ballistic Research Laboratory, APG, MD. Lines: 22 In article <442@newmedia.UUCP> jim@newmedia.UUCP (Jim Beveridge) writes: >If I make the declaration, "struct junk *g;" after the extern above, >it compiles correctly even though "struct junk" doesn't exist. struct junk *g; declares that g is a pointer to a struct tagged "junk" (that in this case has not yet had its members declared). This is one instance of an "incomplete type". If the program is to make any use of the type that requires a complete type, e.g. sizeof(*g), then there must be another declaration that completes the type before it is used. If the type is never needed for anything, it need not be completed. There are two other loosely related points: The standard seems to say that all structure/union/enum tags and typedef names used in prototype parameter declarations have prototype scope, but I think that is not the intention; rather if a declarator was included it is just the identifier in the declarator portion that has prototype scope, not one in the type-specifier portion. (This would be worth getting a formal interpretation ruling on.) The other point is that all pointers to struct turn out to have to have similar representations (at least so many of us think), so a pointer to any kind of struct would be good enough for the compiler and it may not notice that you never declare what the particular kind you actually referred to actually looks like.