From -5053006235722756579 X-Google-Thread: f78e5,1130823ffefc6ebe X-Google-Thread: fc772,1130823ffefc6ebe X-Google-Attributes: gidf78e5,gidfc772,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed-east.nntpserver.com!nntpserver.com!newsfeed1.sea.pnap.net!newsfeed2.sea.pnap.net!newsfeed.pnap.net!brmea-news-1.sun.com!news1nwk.sfbay.sun.com!taumet!clamage From: Bob Hairgrove Newsgroups: comp.std.c++,comp.lang.c++.moderated Subject: Re: Unions up in arms! Date: Sat, 11 Sep 2004 15:30:44 +0000 (UTC) Organization: Cablecom Newsserver Lines: 71 Sender: cppmods@netlab.cs.rpi.edu Approved: stephen.clamage@sun.com (comp.std.c++) Message-ID: References: <9215d7ac.0409081832.4ab088d6@posting.google.com> NNTP-Posting-Host: taumet.sfbay.sun.com Content-Type: TEXT/PLAIN X-Trace: news1nwk.SFbay.Sun.COM 1094916644 8748 129.146.79.208 (11 Sep 2004 15:30:44 GMT) X-Complaints-To: usenet@news1nwk.sfbay.sun.com NNTP-Posting-Date: Sat, 11 Sep 2004 15:30:44 +0000 (UTC) X-Original-NNTP-posting-date: Sat, 11 Sep 2004 05:02:16 +0000 (UTC) Delivered-to: std-c++@ucar.edu X-Original-Date: Fri, 10 Sep 2004 17:58:20 +0200 X-Submission-Address: c++-submit@netlab.cs.rpi.edu X-Auth: PGPMoose V1.1 PGP comp.lang.c++.moderated iQBVAwUAQUKHpEHMCo9UcraBAQF1ygH/UBPLq+5HsXImo1Cjy6M7hIzLQ9Ebz6dw NT9F1ghV2ZG66qv/WB4fjrMvcHO62PmDjxudiIIvvr9oH2O97nFs9Q== =mZWC X-Approved-For-Group: kuehl@inf.uni-konstanz.de comp.lang.c++.moderated X-Original-NNTP-posting-host: netlab.cs.rpi.edu Original-recipient: rfc822;stephen.clamage@sun.com Originator: clamage@taumet Xref: g2news1.google.com comp.std.c++:2544 comp.lang.c++.moderated:7991 On Fri, 10 Sep 2004 15:13:17 +0000 (UTC), glenlow@pixelglow.com (Glen Low) wrote: > >Color me stupid, but after months of staring I still can't grok this >clause in the Standard 3.10/15: > >---- > >If a program attempts to access the stored value of an object through >an lvalue of other than one of the following types the behavior is >undefined: > >an aggregate or union type that includes one of the aforementioned >types among its members (including, recursively, a member of a >subaggregate or contained union), > >---- > >Suppose > >int j; >union u { int i; float f; }; > >Then which of the following is illegal, if any, and why? (Putting >aside, if possible, the legality of the popular type-punning practice >of putting x into a union and getting back y.) > >A. > >j = 12; >int k = ((u&) j).i; > >B. > >j = 12; >u v = (u&) j; > >C. > >u v = {12}; >float g = v.f; > >D. > >j = 12; >float g = ((u&) j).f; Aren't you making a fairly big assumption? What if sizeof(int) != sizeof(float)? >And finally, what does "including, recursively, a member of a >subaggregate or contained union" mean? Just what it says. -- Bob Hairgrove NoSpamPlease@Home.com [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] [ 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 ]