Article View: comp.std.c
Article #1670Re: Scope of incomplete types
From: Doug Gwyn
Date: Mon, 10 Sep 1990 15:01
Date: Mon, 10 Sep 1990 15:01
59 lines
2870 bytes
2870 bytes
In article <1990Sep9.194037.346@charis.UUCP> wmmiller@cup.portal.com writes:
> struct X* p1;
> void f() {
> struct X* p2;
> p2 = p1; /* A */
> }
> struct X { int i; }; /* B */
This is strictly conforming, and all three occurrences of "X" refer to
the same structure type, which is complete at comment B.
As an interesting contrast, consider
struct X* p1;
void f() {
struct X* p2;
struct X { char i; };/* C */
struct X* p3;
p2 = p1; /* A */
} /* D */
struct X { int i; }; /* B */
In this example, p1 and p2 have the same struct type, as before, but
p3 has a different struct type since the declaration ending at comment C
declares a new type. At comment A, "struct X" refers to a complete type
like the type of p3, different from the (still incomplete, as it happens)
type of p1 and p2. Note also that at comment D "struct X" is still an
incomplete type, because the new type at comment C does not propagate
out of the scope within which it was declared (function-body block).
It is also worth noting that the description of the properties of the
special form of declaration
struct-or-union identifier ;
in 3.5.2.3 is NOT a deduction from other specifications, but specifies
a special case (i.e. "kludge") that was adopted specifically for the
purpose of hiding any declaration of the tag name in an outer scope.
Thus, in the example
struct X* p1;
void f() {
struct X; /* E */
struct X* p2;
struct X { char i; };/* C */
struct X* p3;
p2 = p1; /* A */
} /* D */
struct X { int i; }; /* B */
The type of both p2 and p3 will be that of the structure described at
comment C, since the declaration at E starts a new type with tag "X"
unrelated to the tag on the declaration of p1. (This form is like a
declaration with struct-declarator-list in that it begins a new type,
but unlike that in that it is an incomplete type.)
P.S. This is how I read the standard and how I recall the discussion
in X3J11; it is possible that an official interpretation could differ.
For an official interpretation, you should send your query to X3J11 via
the CBEMA X3 Secretariat. X3J11 meets again on the 24th of September,
so if you need an official interpretation ruling soon, you should hurry.
Technical Details
Message-ID:
<13797@smoke.BRL.MIL>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!watserv1!watmath!att!tut.cis.ohio-state.edu!snorkelwacker!usc!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!haven!adm!smoke!gwynReferences:
<1990Sep5.191221.5118@charis.UUCP> <13765@smoke.BRL.MIL> <1990Sep9.194037.346@charis.UUCP>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!watserv1!watmath!att!tut.cis.ohio-state.edu!snorkelwacker!usc!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!haven!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn) Newsgroups: comp.std.c Subject: Re: Scope of incomplete types Message-ID: <13797@smoke.BRL.MIL> Date: 10 Sep 90 15:01:07 GMT References: <1990Sep5.191221.5118@charis.UUCP> <13765@smoke.BRL.MIL> <1990Sep9.194037.346@charis.UUCP> Organization: U.S. Army Ballistic Research Laboratory, APG, MD. Lines: 59