public inbox for gcc-prs@sourceware.org help / color / mirror / Atom feed
From: Gary.Jenkins@tellabs.com To: gcc-gnats@gcc.gnu.org Subject: c++/7023: C++ structure initialization problem if too few initializers given Date: Thu, 13 Jun 2002 12:36:00 -0000 [thread overview] Message-ID: <20020613193036.23467.qmail@sources.redhat.com> (raw) >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==
next reply other threads:[~2002-06-13 19:36 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2002-06-13 12:36 Gary.Jenkins [this message] 2002-09-14 14:50 nathan
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20020613193036.23467.qmail@sources.redhat.com \ --to=gary.jenkins@tellabs.com \ --cc=gcc-gnats@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).