home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 32,730 of 33,346   
   Johannes Sixt to b...@ingen.ddns.info.invalid   
   Re: Fun with unions   
   14 Dec 12 09:00:57   
   
   ee67e53e   
   From: j6t@kdbg.org   
      
   On 13 Dez., 15:09, Bart van Ingen Schenau   
    wrote:   
   > On Wed, 12 Dec 2012 19:42:48 -0800, fmatthew5876 wrote:   
   > > But how about this:   
   >   
   > > union B {   
   > > float x;   
   > > struct {   
   > > float r;   
   > > };   
   > > };   
   >   
   > > Do the members x and the anonymous struct containing r have a "common   
   > > initial sequence" namely of a single float?   
   >   
   > No, they don't have a "common initial sequence", because x is not a   
   > member of a struct (which in turn would be a member of the union). So   
   > technically the results would not be guaranteed if you write to r and   
   > then read the value of x.   
   > But, a compiler would have to go out of its way to give it other behaviour   
   > than that which is mandated for common initial sequences, because the   
   > assertion "B b; assert(&b.x == &b.r);" must still hold.   
      
   But this is still not immune against aliasing problems: If you write a new   
   value to x, then read from r, you trigger undefined behavior as per 3.10p10   
   because of the lack of other guarantees, no?   
      
   -- Hannes   
      
      
   --   
         [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
         [ comp.lang.c++.moderated.    First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca