Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2012
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.54 KB | None | 0 0
  1. /*
  2.  * # gcc main.c -o main
  3.  * # ./main
  4.  * Size results:
  5.  *
  6.  * struct: 9
  7.  * int #1: 4
  8.  * int #2: 4
  9.  * char #1: 1
  10.  */
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14.  
  15. typedef struct Test
  16. {
  17.         int a;
  18.         int b;
  19.         char c;
  20. } __attribute__((packed)) Test;
  21.  
  22. int main(void)
  23. {
  24.         Test *obj = (Test*)malloc(sizeof(Test));
  25.  
  26.         printf("Size results:\r\n\r\nstruct: %i\r\nint #1: %i\r\nint #2: %i\r\nchar #1: %i\r\n",
  27.                 sizeof(Test), sizeof(obj->a), sizeof(obj->b), sizeof(obj->c));
  28.  
  29.         return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement