rvelthuis

Union sizes

Feb 11th, 2015
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.64 KB | None | 0 0
  1. #pragma hdrstop
  2. #include <stdio.h>
  3. #include <conio.h>
  4.  
  5. union TUnion
  6. {
  7.      struct
  8.      {
  9.          unsigned char b1, b2, b3;
  10.      };
  11.      struct
  12.      {
  13.          unsigned short w1;
  14.      };
  15. } TUnion;
  16.  
  17. struct TDavidsRecord
  18. {
  19.     union TUnion u;
  20.     unsigned char b4;
  21. };
  22.  
  23. union TOriginalUnion
  24. {
  25.     struct
  26.     {
  27.         unsigned char b1, b2, b3;
  28.     };
  29.     struct
  30.     {
  31.         unsigned short w1;
  32.     };
  33. };
  34.  
  35.  
  36. int main(int argc, char *argv[])
  37. {
  38.     printf("sizeof(TDavidsRecord)  = %d\n", sizeof(struct TDavidsRecord));
  39.     printf("sizeof(TOriginalUnion) = %d\n", sizeof(union TOriginalUnion));
  40.     getch();
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment