Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #include <stdlib.h>
- #include <time.h>
- #include <string.h>
- typedef struct {
- char a[16] ;/* 16 octets */
- }align; /* 16 octets */
- typedef struct _noalign {
- char c; /* 1 octet */
- double d; /* 8 octets */
- int i; /* 4 octets */
- char c2[3]; /* 3 octets */
- }__attribute__((packed)) noalign;
- int main()
- {
- align a;
- char b =a.a[0];
- char c[2];
- for (int i = 1 ; i < 3 ; i++) c[i]= a.a[i];
- char d[4];
- for (int i = 4 ; i < 9 ; i++) d[i]= a.a[4];
- char e[8];
- for (int i = 9 ; i < 16 ; i++) e[i]= a.a[8];
- //for (int i = 1 ; i < 9 ; i++) d = d + a.a[i]; faux
- //printf("b = %d c=%d d=%d e= %d\n",sizeof(b),sizeof(c),sizeof(d),sizeof(e));
- printf("noalign packed = %d \n",sizeof(noalign));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement