From -5948544878413999358 X-Google-Thread: f78e5,4176870a6d7b2d6 X-Google-Attributes: gidf78e5,public X-Google-Language: ENGLISH,ASCII-7-bit Return-Path: X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f Path: g2news1.google.com!news2.google.com!news1.google.com!news.glorb.com!cyclone.bc.net!news.alt.net!comp-std-cpp-robomod!not-for-mail X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov) Delivered-To: std-c++@ucar.edu From: Ben Hutchings Newsgroups: comp.std.c++ Subject: Re: Union fun Message-ID: References: Reply-To: Ben Hutchings X-Orig-X-Trace: news.uni-berlin.de tE3z9c+jhOVT0v3REIB5aQEOUaMK9pdCLAtcdpGS3xDSIplnU= X-Orig-Path: decadentplace.org.uk!nobody User-Agent: slrn/0.9.7.4 (Linux) X-Spam-Status: No, hits=-4.9 required=5.0 tests=BAYES_00 autolearn=ham version=2.64-mulga_r1 X-Spam-Checker-Version: SpamAssassin 2.64-mulga_r1 (2004-01-11) on mulga.cs.mu.OZ.AU Approved: Fergus Henderson , moderator of comp.std.c++ Date: Mon, 18 Oct 2004 11:35:01 CST Xref: g2news1.google.com comp.std.c++:3097 "John Max Skaller" wrote: > IMHO: > > union U1 { float a; int b; U1() : a(1.0), b(1); } x; > x.a // undefined > > union U2 { int b; float a; U1() : a(1.0), b(1); } y; > y.a; // 1.0f, well defined > > g++ says his: > > initializations for multiple members of `U' > > I think g++ is wrong. > > Comments? It's right. The standard says in 12.6.2/3: "If a ctor-initializer specifies more than one mem-initializer for the same member, for the same base class or for multiple members of the same union (including members of anonymous unions), the ctor-initializer is ill-formed." -- Ben Hutchings When in doubt, use brute force. - Ken Thompson --- [ comp.std.c++ is moderated. To submit articles, try just posting with ] [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ] [ --- Please see the FAQ before posting. --- ] [ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]