Path: utzoo!attcan!uunet!husc6!necntc!ima!haddock!karl
From: karl@haddock.ISC.COM (Karl Heuer)
Newsgroups: comp.lang.c
Subject: Re: Structure pointer question
Message-ID: <4524@haddock.ISC.COM>
Date: 13 Jun 88 15:54:28 GMT
References: <361@teletron.UUCP> <8074@brl-smoke.ARPA>
Reply-To: karl@haddock.ima.isc.com (Karl Heuer)
Organization: Interactive Systems, Boston
Lines: 24

In article <8074@brl-smoke.ARPA> gwyn@brl.arpa (Doug Gwyn) writes:
>In article <361@teletron.UUCP> andrew@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@haddock.isc.com), The Walking Lint