Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main ()
- {
- struct st1{
- char a;
- char* a1;
- char* a2;
- };
- struct st2{
- char a;
- char* a1 __attribute__ ((packed));
- char* a2 __attribute__ ((packed));
- };
- struct st3{
- int a;
- char* a1;
- char* a2;
- };
- struct st4{
- int a;
- char* a1 __attribute__ ((packed));
- char* a2 __attribute__ ((packed));
- };
- struct st5{
- char a __attribute__ ((aligned (16)));
- char* a1 __attribute__ ((aligned (16)));
- char* a2 __attribute__ ((aligned (16)));
- };
- struct st6{
- char a;
- char* a1;
- char* a2;
- } __attribute__ ((aligned (32)));
- printf("sizeof int: %zu\n", sizeof(int));
- printf("sizeof char*: %zu\n", sizeof(char*));
- printf("(1) %zu\n", sizeof (struct st1));
- printf("(2) %zu\n", sizeof (struct st2));
- printf("(3) %zu\n", sizeof (struct st3));
- printf("(4) %zu\n", sizeof (struct st4));
- printf("(5) %zu\n", sizeof (struct st5));
- printf("(6) %zu\n\n", sizeof (struct st6));
- }
- /*
- output:
- sizeof int: 4
- sizeof char*: 8
- (1) 24
- (2) 17
- (3) 24
- (4) 20
- (5) 48
- (6) 32
- */
Advertisement