Article View: comp.std.c
Article #83Re: int foo[]; vs. extern int foo[];
From: John F. Woods
Date: Mon, 03 Aug 1992 18:55
Date: Mon, 03 Aug 1992 18:55
51 lines
2544 bytes
2544 bytes
bill@twwells.com (T. William Wells) writes:
>If I'm reading the (May 88 draft) standard correctly, when each
>is the only declaration, int foo[]; is equivalent to int foo[] =
>0; and either is an error or an array of one element depending on
>exactly how one interprets the wording. Extern int foo[];,
>however, does what one expects, declaring an array of unknown
>size.
Depending on how you want it, they may or may not have "fixed" it.
"A declaration of an identifier for an object that has file scope without an
initializer, and without a storage-class specifier or with the storage-class
specifier *static*, constitutes a _tentative_definition_. If a translation
unit contains one or more tentative definitions for an identifier, and the
translation unit contains no external definition for that identifier, then
the behavior is exactly as if the translation unit contains a file scope
declaration of that identifier, with the composite type as of the end of the
translation unit, with an initializer equal to 0.
If the declaration of an identifier for an object is a tentative definition
and has internal linkage, the declared type shall not be an incomplete type."
So,
static int foo[];
is illegal, but
int foo[];
standing all by itself means
int foo[] = {0};
when the translation unit ends without further clarification.
If your complaint is that it could be an error, that's been fixed, as near
as I can tell. If your complaint is that it means something silly, well,
given that you can achieve exactly what is wanted merely by typing
extern int foo[];
it doesn't really seem like a problem.
I suppose it might be considered a problem that 3.7.2 specifies that the
initializer is "equal to 0", which might or might not be seen as equal to
"{0}" as is necessary to initialize an array, but I think the clarification
under "Semantics" in 3.5.7 ("If an object that has static storage duration
is not initialized explicitly, it is initialized implicitly as if every
member that has arithmetic type were assigned 0 and every member that has
pointer type were assigned a null pointer constant.") adequately blesses
the necessary interpretation.
Technical Details
Message-ID:
<14383@ksr.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!sdd.hp.com!usc!sol.ctr.columbia.edu!eff!world!ksr!jfwReferences:
<Bs938o.54A@twwells.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!sdd.hp.com!usc!sol.ctr.columbia.edu!eff!world!ksr!jfw From: jfw@ksr.com (John F. Woods) Newsgroups: comp.std.c Subject: Re: int foo[]; vs. extern int foo[]; Message-ID: <14383@ksr.com> Date: 3 Aug 92 14:55:53 EDT References: <Bs938o.54A@twwells.com> Sender: news@ksr.com Lines: 51