Path: utzoo!attcan!uunet!tut.cis.ohio-state.edu!zaphod.mps.ohio-state.edu!sdd.hp.com!decwrl!shlump.nac.dec.com!tkou02.enet.dec.com!diamond From: diamond@tkou02.enet.dec.com (diamond@tkovoa) Newsgroups: comp.std.c Subject: Re: pointer to incomplete type? Message-ID: <1773@tkou02.enet.dec.com> Date: 7 Jun 90 00:54:42 GMT References: <13048@smoke.BRL.MIL> <7565@ncar.ucar.edu> Reply-To: diamond@tkou02.enet.dec.com (diamond@tkovoa) Organization: Digital Equipment Corporation Japan , Tokyo Lines: 33 In article <7565@ncar.ucar.edu> steve@groucho.ucar.edu (Steve Emmerson) writes: >In <13048@smoke.BRL.MIL> gwyn@smoke.BRL.MIL (Doug Gwyn) writes: >>In article <1680@mcrware.UUCP> jejones@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@tkou02.enet.dec.com Proposed group comp.networks.load-reduction: send your "yes" vote to /dev/null.