CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 18 of 18

Thread: union

  1. #16
    Join Date
    Feb 2002
    Posts
    4,640

    Re: union

    Quote Originally Posted by ninja9578 View Post
    I didn't say that the example I posted was that case, I was just saying that it's a more advanced case, that might be undefined.

    What would happen here?

    Code:
    union foo {
       bool b;
       short s;
       int i;
    };
    Is it defined where the bits for each are stored, or is that up to the compiler?
    I believe that's compile dependent. I think...

    Viggy

  2. #17
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: union

    As I read this http://www.open-std.org/jtc1/sc22/wg...2011/n3242.pdf (page 226, §5) each member in a union should have the same address so the mapping is defined. Endian has to be considered though.
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

  3. #18
    Join Date
    Feb 2002
    Posts
    4,640

    Re: union

    That's right, each member in the union starts at the same address.

    Viggy

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured