pointer to incomplete type?

diamond@tkovoa diamond at tkou02.enet.dec.com
Thu Jun 7 10:54:42 AEST 1990


In article <7565 at ncar.ucar.edu> steve at groucho.ucar.edu (Steve Emmerson) writes:
>In <13048 at smoke.BRL.MIL> gwyn at smoke.BRL.MIL (Doug Gwyn) writes:
>>In article <1680 at mcrware.UUCP> jejones at mcrware.UUCP (James Jones) writes:
>>>how can one safely declare a pointer to an incomplete structure, union, or
>>>enumerated type?
>>The type must be complete before any use that depends on it.

Doug Gwyn didn't exactly answer James Jones' question.  Thus Steve
Emmerson's confusion:

>	In file foo.h:
>		typedef struct FooTag	*FooPtr;
>		extern FooPtr		FooCreate();
>		extern void		FooFree(FooPtr foo);

This will work, because clients use only pointers.  A pointer type
is complete, even if the pointed-to type is not complete yet.
If clients try to use *FooCreate() or FooCreate()->someMember,
or if there is a declaration FooOp(struct FooTag someFoo),
then clients will get in trouble because the struct type is incomplete.

>The rationale for this is that clients using the "foo" ADT include
>"foo.h" and pass variables of type "FooPtr" around but are otherwise
>prevented from knowing any details of its implementation (no style 
>flames please).

This is a perfectly reasonable thing to do.  Now, what kind of goof are
you, resorting to begging "no style flames please" instead of using clear
arguments to properly justify this approach?  ( :-) Teasing only.)

-- 
Norman Diamond, Nihon DEC     diamond at tkou02.enet.dec.com
Proposed group comp.networks.load-reduction:  send your "yes" vote to /dev/null.



More information about the Comp.std.c mailing list