Article View: comp.std.c
Article #4368Re: "Size not needed?"
From: Richard Krehbiel
Date: Fri, 17 Nov 1995 12:12
Date: Fri, 17 Nov 1995 12:12
37 lines
1598 bytes
1598 bytes
Paul Long <plong@perf.com> wrote:
>Section 6.5.2.3 says, "If a type specifier of the form _struct-or-union
>identifier_ occurs prior to the declaration that defines the content, the
>structure or union is an incomplete type. It declares a tag that specifies a
>type that may be used only when the size of an object of the specified type is
>not needed."
>What does "the size...is not needed" mean? "Needed" sounds awfully vague. For
>example, is the size needed here?
> struct S x;
> void foo() { x; }
>I don't think so, but perhaps this is implementation-dependent.
I think the size is needed, but not because of the reference in foo(),
but because of the way it's defined. Since x is of static storage
class, the language is obliged to initialize it, and it can't without
knowing the size.
If you used "extern struct S x;" then the size is not needed. I would
expect the following to be fully legal:
extern struct S x, y;
struct S *pickS(int pick)
{
if(pick)
return &x;
else
return &y;
}
--
Richard Krehbiel, Kastle Systems, Arlington VA USA
rich@kastle.com (work) or richk@cais.com (personal)
Technical Details
Message-ID:
<1995Nov17.120551.23493@friend.kastle.com>Path:
arc1-ca.pugleaf.net!uu4news.netcom.com!friend!newsReferences:
<48gu0r$91o@news0.rain.rg.net>Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c Path: arc1-ca.pugleaf.net!uu4news.netcom.com!friend!news From: rich@kastle.com (Richard Krehbiel) Subject: Re: "Size not needed?" Message-ID: <1995Nov17.120551.23493@friend.kastle.com> Sender: news@friend.kastle.com (News) Reply-To: rich@kastle.com Organization: Kastle Development Associates X-Newsreader: Forte Free Agent 1.0.82 References: <48gu0r$91o@news0.rain.rg.net> Date: Fri, 17 Nov 1995 12:12:02 GMT