Advertisement
mario_mos

packed

Jul 26th, 2023
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <stdlib.h>
  4. #include <time.h>
  5. #include <string.h>
  6.  
  7.  
  8.  
  9. typedef struct {
  10. char a[16] ;/* 16 octets */
  11. }align; /* 16 octets */
  12.  
  13. typedef struct _noalign {
  14. char c; /* 1 octet */
  15. double d; /* 8 octets */
  16. int i; /* 4 octets */
  17. char c2[3]; /* 3 octets */
  18. }__attribute__((packed)) noalign;
  19.  
  20.  
  21. int main()
  22. {
  23. align a;
  24. char b =a.a[0];
  25. char c[2];
  26. for (int i = 1 ; i < 3 ; i++) c[i]= a.a[i];
  27. char d[4];
  28. for (int i = 4 ; i < 9 ; i++) d[i]= a.a[4];
  29. char e[8];
  30. for (int i = 9 ; i < 16 ; i++) e[i]= a.a[8];
  31. //for (int i = 1 ; i < 9 ; i++) d = d + a.a[i]; faux
  32. //printf("b = %d c=%d d=%d e= %d\n",sizeof(b),sizeof(c),sizeof(d),sizeof(e));
  33. printf("noalign packed = %d \n",sizeof(noalign));
  34.  
  35.  
  36.  
  37. return 0;
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement