Path: utzoo!attcan!uunet!mcvax!hp4nl!philmds!leo From: leo@philmds.UUCP (Leo de Wit) Newsgroups: comp.lang.c Subject: Re: incomplete types (was: Recursive #includes) Message-ID: <979@philmds.UUCP> Date: 17 Mar 89 17:50:37 GMT References: <570@marob.MASA.COM> <9727@smoke.BRL.MIL> <964@philmds.UUCP> <976@philmds.UUCP> <884@m10ux.UUCP> Reply-To: leo@philmds.UUCP (Leo de Wit) Organization: Philips I&E DTS Eindhoven Lines: 55 In article <884@m10ux.UUCP> mnc@m10ux.UUCP (Michael Condict) writes: |In article <976@philmds.UUCP>, leo@philmds.UUCP (Leo de Wit) writes: [] self-contained cross-referencing struct example omitted ... |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. There's no such thing as declaration scoped types (if there is I would be very interested to know where you got that information); the scope of struct hen is the same as the scope of struct egg (the same block of whatever). | 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? Yes, exactly as it stands. I would be very surprised if (draft) ANSI conformant compilers couldn't handle this. And the C compilers I've seen do treat it correctly. |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. Ah, that's the real problem. Perhaps you're having trouble reading this declaration. As a matter of fact, I have used such declarations more than once (although one doesn't need cross-referencing structures every day), and I never found it awkward nor confusing. The declaration not being symmetrical is more a style issue. |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. Something like this? struct egg { struct hen { struct chicken { struct egg *eggp; } *chickenp; } *henp; }; | Things like struct tags that are global, should be declared only |globally, i.e. outside of any function or other struct. Struct tags? The struct _type_ (nl. struct hen) is what we are discussing (the tag 'henp' is also available being a member of the struct egg, but that's not the point), and as I pointed out before, has the same scope as the struct egg. Leo.