#include <stdio.h> typedef struct{ char data[261]; int n; } packet; int main(int argc, char *argv[]){ packet p; //It should print packet=265... it prints packet=268 printf("packet = %d\n", sizeof(packet)); //It should print p=265... it prints p=268 printf("p = %d\n", sizeof(p)); //It should print p.n=4... OK printf("p.n = %d\n", sizeof(p.n)); //It should print p.data=261... OK printf("p.data = %d\n", sizeof(p.data)); return 0; }
Learn about alignment when doing struct layout. Basically you want to use the attribute packed to get the sizes you want.