Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!bellcore!faline!thumper!ulysses!mhuxo!mhuxu!m10ux!mnc From: mnc@m10ux.UUCP (Michael Condict) Newsgroups: comp.lang.c Subject: Re: incomplete types (was: Recursive #includes) Summary: incomplete types are essential Message-ID: <884@m10ux.UUCP> Date: 14 Mar 89 19:58:28 GMT References: <570@marob.MASA.COM> <9727@smoke.BRL.MIL> <964@philmds.UUCP> <976@philmds.UUCP> Organization: AT&T Bell Labs, Murray Hill Lines: 37 In article <976@philmds.UUCP>, leo@philmds.UUCP (Leo de Wit) writes: - In article <9842@smoke.BRL.MIL> gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) writes: - |There is nothing inherently "bad" about incomplete types, especially - |incomplete structure declarations. In fact they are essential for - |declaring structures that contain pointers to each other. - - How essential that is? Consider: - - struct egg { - struct hen { - struct egg *eggp; - } *henp; - }; - - This declares two structure types, each containing a pointer to the - other one. And I can give more complex examples ... Yes, but in the example you show, the scope of the "struct hen" tag declaration might be limited to the inside of the "struct egg" declaration, depending on your C compiler and the rules of ANSI-C. Can you show us how to declare these two structs, hen and egg, such that both are guaranteed by the rules of ANSI-C and current C compilers to be accessible after the declaration, without using incomplete types? Even if the above example declares the two tags egg and hen globally, it is awkward and confusing to have to arbitrarily declare one inside the other. It will only lead to very confusing error messages when you try to add another mutually recursive struct declaration and don't get the ordering or the nesting right. Things like struct tags that are global, should be declared only globally, i.e. outside of any function or other struct. By the way, can someone tell me if the above code defines "struct hen" globally in ANSI-C? -- Michael Condict {att|allegra}!m10ux!mnc AT&T Bell Labs (201)582-5911 MH 3B-416 Murray Hill, NJ