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,235 of 33,346   
   Pete Becker to Gil N.   
   Re: Union padding   
   02 May 12 23:09:10   
   
   cb21380f   
   From: pete@versatilecoding.com   
      
   On 2012-05-02 19:08:41 +0000, Gil N. said:   
      
   > { quoted clc++m banner removed -mod }   
   > you're not accurate, all data members of an union must begin at the   
   > same   
   > address; it is a fundamental property of an union.   
   > this is guaranteed by the C Standard which is normative for C++ unless   
   > otherwise explicitly specified.   
      
   No, it's the other way around: some parts of the C standard are explicitly   
   incorporated into C++.   
      
   > read for example ANSI/ISO 9899:1990 6.5.2.1, truncated below:   
   > "A pointer to a union object, suitably converted, points to each of   
   > its   
   > members (or if a member is a bit-field, then to the unit in which it   
   > resides), and vice versa."   
   > note: if you don't want to buy the C standard too you can use C++11   
   > standard, read   
      
   Even if you have the C standard, C++ is defined by the C++ standard .   
      
   And this is the key:   
      
   > 5.9.2 "If two pointers point to non-static data members of the same   
   > union object, they compare equal (after conversion to void*, if   
   > necessary)."   
      
   It's an odd place to put such a requirement, though.   
      
   --   
   Pete   
   Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The Standard   
   C++ Library Extensions: a Tutorial and Reference (www.petebecker.com/tr1book)   
      
      
         [ 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