forward declared structures
Mike Rubenstein
mmr at utmbvax.UUCP
Wed Aug 8 08:21:16 AEST 1984
> 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
More information about the Comp.lang.c
mailing list