Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site utmbvax.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxl!houxm!houxz!vax135!cornell!uw-beaver!tektronix!hplabs!hao!seismo!ut-sally!utmbvax!mmr From: mmr@utmbvax.UUCP (Mike Rubenstein) Newsgroups: net.lang.c Subject: Re: forward declared structures Message-ID: <358@utmbvax.UUCP> Date: Tue, 7-Aug-84 18:21:16 EDT Article-I.D.: utmbvax.358 Posted: Tue Aug 7 18:21:16 1984 Date-Received: Sun, 12-Aug-84 00:42:58 EDT References: <226@siemens.UUCP> <884@bbncca.ARPA>, <353@utmbvax.UUCP> <136@byucsb.UUCP> Organization: U. Texas Medical Branch, Galveston, Texas Lines: 19 > The problem with: > struct foo { struct bar *b; }; > struct bar { struct foo *f; }; > is that it allows a procedure to appear between them (at the global level). > If this is rewritten as: > struct foo { struct bar { struct foo *f; } *b; }; > then any "forward reference" refers to a partially-declared struct/union > and makes it easier for the compiler to detect such typos as: > struct foo { struct bar { struct foo f; } *b; }; Unfortunately, at the cost of obscuring the code, at least in many cases. In the case I ran into the structures (which, of course, actually had other members) were for two tables which needed cross references into each other. It would, I think, have been misleading to make the code look like one was subordinate to the other. I don't think it's worth it to make the compiler's job a bit easier. -- Mike Rubenstein, OACB, UT Medical Branch, Galveston TX 77550