Structure pointer question

Karl Heuer karl at haddock.ISC.COM
Tue Jun 14 01:54:28 AEST 1988


In article <8074 at brl-smoke.ARPA> gwyn at brl.arpa (Doug Gwyn) writes:
>In article <361 at teletron.UUCP> andrew at teletron.UUCP (Andrew Scott) writes:
>>Is it alright to #include "foo.h" and not "bar.h" in a source file if the
>>fields of "struct bar" are not used?

I believe the answer is Yes.  (As noted, it depends on all struct pointers
having the same format, but this is implicitly required by the language.)

>Technically not, because the "struct foo" type remains incomplete until
>you declare a complete type for "struct bar".

I hate to contradict Doug, but I believe that (a) he's wrong, and (b) even if
he's right, it doesn't matter.

(a) struct foo was defined to contain a *pointer* to a struct bar, not an
actual struct bar.  A type is incomplete only if its size is unknown; this is
true of bar, but not foo.

(b) There's no rule that forbids having incomplete types in a program.  They
only need to be completed if the missing information is required.  The
incomplete type (obtained by including foo.h) and the complete type (obtained
by also including bar.h) are compatible types.

Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint



More information about the Comp.lang.c mailing list