🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #1647

Re: Scope of incomplete types

#1647
From: Doug Gwyn
Date: Fri, 07 Sep 1990 15:49
32 lines
1981 bytes
In article <1990Sep5.191221.5118@charis.UUCP> wmmiller@cup.portal.com writes:
>                struct X* xp1;
>                {
>                   struct X* xp2;
>                   }

Neither of these declares a struct X.  That is a crucial point to
understand in conjunction with the example from 3.5.2.3 that you cited.

>... there doesn't appear to be anything in the Standard to indicate any
>difference in the way the scope rules apply to incomplete types.

That's correct; visibility of an identifier (scope) is not affected by
incompleteness of its type.

>        If the type is to be completed, another declaration of the tag in
>        the same scope (but not in an enclosed block, which declares a new
>        type known only within that block) shall define the content.

Yes, basically one of the interesting things X3J11 figured out at the
first interpretation-phase meeting was that the standard insists that
type information is not propagated outward from a block.  That has all
sorts of subtle ramifications, fortunately not affecting programmers
who use sensible coding style in the first place.

For your example, basically I would say that not declaring what a struct X
really is before declaring pointers to it is a poor practice except in the
case of mutually-referential structures as in the 3.5.2.3 example, and even
there one should as a matter of safety predeclare an incomplete type like:
	struct s2;	/* forces s2 to refer to the one in the current scope */
	struct s1 { struct s2 *s2p; /*...*/ };
	struct s2 { struct s1 *s1p; /*...*/ };
Technical Details
Message-ID: <13765@smoke.BRL.MIL>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!yale!cmcl2!adm!smoke!gwyn
References: <1990Sep5.191221.5118@charis.UUCP>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!yale!cmcl2!adm!smoke!gwyn
From: gwyn@smoke.BRL.MIL (Doug Gwyn)
Newsgroups: comp.std.c
Subject: Re: Scope of incomplete types
Message-ID: <13765@smoke.BRL.MIL>
Date: 7 Sep 90 15:49:17 GMT
References: <1990Sep5.191221.5118@charis.UUCP>
Organization: U.S. Army Ballistic Research Laboratory, APG, MD.
Lines: 32