Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!ncar!groucho!steve From: steve@groucho.ucar.edu (Steve Emmerson) Newsgroups: comp.std.c Subject: Re: pointer to incomplete type? Message-ID: <7565@ncar.ucar.edu> Date: 6 Jun 90 18:50:09 GMT References: <13048@smoke.BRL.MIL> Sender: news@ncar.ucar.edu Organization: University Corporation for Atmospheric Research (UCAR) Lines: 45 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. Along this line, and in view of expressed, differing opinions on the subject and my own, subsequent, confusion, I like to post the following question: Is the following legal ANSI C? In file foo.h: typedef struct FooTag *FooPtr; extern FooPtr FooCreate(); extern void FooFree(FooPtr foo); In file foo.c: #include "foo.h" typedef struct FooTag { } FooThing; ... void FooFree(FooPtr foo) { } 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). One poster indicated that -- strictly speaking -- this was not legal. Is this true? Or does the use of "FooPtr" in a client not depend on its being a complete type? Steve Emmerson steve@unidata.ucar.edu ...!ncar!unidata!steve