Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Kaz Kylheku <kaz@kylheku.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Using ternary and summing array |
| Date | 2011-11-03 17:03 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <20111103121523.385@kylheku.com> (permalink) |
| References | <26bf4806-b232-4878-810b-55f3d3926c9f@p20g2000prm.googlegroups.com> <9f0bff2f-ccec-4c4d-ae8d-aef2a45216fb@s2g2000yqd.googlegroups.com> <BNCdnQuM3pwLJi_TnZ2dnUVZ_vSdnZ2d@bestweb.net> |
On 2011-11-03, Kenneth Brody <kenbrody@spamcop.net> wrote:
> Note that my compiler creates a[] with zero members.
>
> However, my compiler acts "strange" on this point.
>
>==========
> #include <stdio.h>
>
> int a[];
>
> int main(void)
> {
> printf("%ld\n",(long)sizeof(a));
> }
>==========
Do you have some tools so you see what the size of a is in the translated
object file? (Is it in the object file?)
This might be a degenerate case which has no meaning due to a possible flaw in
the standard.
Under 6.9.2 we have this text:
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.
But an array cannot have an initializer equal to 0:
int a[] = 0; // invalid!
The second example for this section states the intent:
If at the end of the translation unit containing
int i[];
the array i still has incomplete type, the implicit initializer causes it to
have one element, which is set to zero on program startup.
This would be the case if the implicit initializer were { 0 }. The intent
is clear from the example, but for the text to bear it out, we have to
believe that "an initializer equal to zero" refers to a specific choice
of initializer such as { 0 }.
> Further investigation shows that my compiler seems to treat "int a[];" the
> same as "extern int a[];". Is that "legal"?
I would avoid this situation, since only a non-normative example gives it
a clear meaning.
Compiler writers, however, should pay careful attention to examples and
footnotes.
What does your compiler do if, at the end of the translation unit, you
add:
int a[] = { 0 };
?
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Using ternary and summing array flebber <flebber.crue@gmail.com> - 2011-10-31 03:35 -0700
Re: Using ternary and summing array flebber <flebber.crue@gmail.com> - 2011-10-31 04:06 -0700
Re: Using ternary and summing array Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-10-31 15:06 +0000
Re: Using ternary and summing array pete <pfiland@mindspring.com> - 2011-11-01 04:37 -0500
Re: Using ternary and summing array Keith Thompson <kst-u@mib.org> - 2011-11-01 16:36 -0700
Re: Using ternary and summing array flebber <flebber.crue@gmail.com> - 2011-10-31 04:04 -0700
Re: Using ternary and summing array Jean-Christophe <5.d@free.fr> - 2011-10-31 04:16 -0700
Re: Using ternary and summing array Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-10-31 15:00 +0000
Re: Using ternary and summing array flebber <flebber.crue@gmail.com> - 2011-10-31 16:11 -0700
Re: Using ternary and summing array James Kuyper <jameskuyper@verizon.net> - 2011-10-31 21:49 -0400
Re: Using ternary and summing array Kenneth Brody <kenbrody@spamcop.net> - 2011-11-03 12:04 -0400
Re: Using ternary and summing array Kaz Kylheku <kaz@kylheku.com> - 2011-11-03 17:03 +0000
Re: Using ternary and summing array Kenneth Brody <kenbrody@spamcop.net> - 2011-11-08 13:08 -0500
Re: Using ternary and summing array James Kuyper <jameskuyper@verizon.net> - 2011-10-31 07:46 -0400
Re: Using ternary and summing array David Thompson <dave.thompson2@verizon.net> - 2011-11-21 02:39 -0500
csiph-web