🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #1401

Re: pointer to incomplete type?

#1401
From: Steve Emmerson
Date: Wed, 06 Jun 1990 18:50
45 lines
1683 bytes
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 {
		    <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@unidata.ucar.edu        ...!ncar!unidata!steve
Technical Details
Message-ID: <7565@ncar.ucar.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!mailrus!ncar!groucho!steve
References: <13048@smoke.BRL.MIL>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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