public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c++/7023: C++ structure initialization problem if too few initializers given
@ 2002-06-13 12:36 Gary.Jenkins
0 siblings, 0 replies; 2+ messages in thread
From: Gary.Jenkins @ 2002-06-13 12:36 UTC (permalink / raw)
To: gcc-gnats
>Number: 7023
>Category: c++
>Synopsis: C++ structure initialization problem if too few initializers given
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu Jun 13 12:36:06 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: Gary Jenkins
>Release: egcs-2.91.60
>Organization:
>Environment:
SunOS sunbc6148 5.6 Generic_105181-23 sun4u sparc SUNW,Ultra-5_10
>Description:
Problem:
Structure initialization doesn't seem to work correctly if you get too
few initializers.
Expected Behavior:
If too few initializers are given, unspecified structure members
should be initialized with zero.
Example:
struct Foo
{
const int a;
const int b;
};
Foo f = { 0 }; // should initilize f.a and f.b to zero
Reference:
C Language
----------
"The ANSI C Programming Language (Second Edition)" , Copyright 1988 by AT&T
Brian W. Kerninghan, Dennis M. Ritchie,
Page 219, section A8.7 "Initialization":
"If there are fewer initializers in the list then members of the structure,
the trailing members are initialized with 0".
C++ Language
------------
This is alluded to but not stated as clearly in the C++ bible:
"The C++ Programming Language (Special Edition", Copyright 2000 by AT&T
Bjarne Stroustrup
Page 89, section 5.2.1 "Array Initializers":
"If the initializer supplies too few elements, 0 is assumed for the
remaining array elements".
Page 102, section 5.7 "Structures"
"The notation used for initializing arrays can also be used for initializing
variables of structure types".
>How-To-Repeat:
File main.cc:
struct Foo
{
const int a;
const int b;
};
int main()
{
Foo f = { 0 }; // error: uninitialized const member `b'
return 0;
}
Compile main.cc:
> g++ main.cc
main.cc: In function `int main()':
main.cc:9: uninitialized const member `b'
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="main.cc"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="main.cc"
c3RydWN0IEZvbwp7CiAgICBjb25zdCBpbnQgYTsKICAgIGNvbnN0IGludCBiOwp9OwoKaW50IG1h
aW4oKQp7CiAgICBGb28gZiA9IHsgMCB9OyAgICAgICAgICAgICAgLy8gZXJyb3I6IHVuaW5pdGlh
bGl6ZWQgY29uc3QgbWVtYmVyIGBiJwoKICAgIHJldHVybiAwOwp9Cg==
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: c++/7023: C++ structure initialization problem if too few initializers given
@ 2002-09-14 14:50 nathan
0 siblings, 0 replies; 2+ messages in thread
From: nathan @ 2002-09-14 14:50 UTC (permalink / raw)
To: Gary.Jenkins, gcc-bugs, gcc-prs, nobody
Synopsis: C++ structure initialization problem if too few initializers given
State-Changed-From-To: open->closed
State-Changed-By: nathan
State-Changed-When: Sat Sep 14 14:50:15 2002
State-Changed-Why:
not a bug. [8.5.1]/7 -> [8.5]/9 -> ill formed
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=7023
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2002-09-14 21:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-06-13 12:36 c++/7023: C++ structure initialization problem if too few initializers given Gary.Jenkins
2002-09-14 14:50 nathan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).