pointer to incomplete type?
Steve Emmerson
steve at groucho.ucar.edu
Thu Jun 7 04:50:09 AEST 1990
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.
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 {
<complete definition>
} FooThing;
...
void
FooFree(FooPtr foo)
{
<destruction code>
}
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 at unidata.ucar.edu ...!ncar!unidata!steve
More information about the Comp.std.c
mailing list