Advertisement
Guest User

Untitled

a guest
Apr 29th, 2017
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.61 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. typedef struct __attribute__((packed))
  4. {
  5.     int elem1;
  6.     long long elem2;
  7.     long elem3;
  8. } teststruct1;
  9.  
  10. typedef struct  __attribute__((packed))
  11. {
  12.     char elem1;
  13.     teststruct1 thestruct;
  14.     char elem3;
  15. } teststruct2;
  16.  
  17. int main()
  18. {
  19.     teststruct2 temp =
  20.     {
  21.         .elem1 = 'a',
  22.         .thestruct =
  23.         {
  24.             1,3,5
  25.         },
  26.         .elem3 = 'b'
  27.     };
  28.     //for confirmation
  29.     printf("actual size of testruct1: %d\n", sizeof(teststruct1));
  30.  
  31.     printf("calculated size of testruct: %d\n", &temp.elem3 - (&temp.elem1 + 1));
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement