compiler construction - C Structure Padding. Nested Structures -
struct y{ int int_one; int int_two; void * pointer; } struct x{ char char_one; char char_two; struct y y_structures[20]; } the padding different on 32 , 64 bit machines. don't know why. far know padding should follows :
0x0 char_one <br> 0x1 char_two <br> 0x4 y_structures[0].int_one <br> 0x8 y_structures[0].int_two <br> 0x12 y_structure[0].pointer <br> the structure on 32 bit similar mentioned above on 64 bit machine difference between addresses of char_two , y_structures[0].int_one 7 bytes. think should 3 bytes because type aligned after char_two int of y_structures[0] , it's size 4 on both architectures. kindly help
the problem not int, it's pointer. pointer have size of 8 bytes on 64bit machines, therefore must start @ memory address mod 8.
0x0 char_one 0x1 char_two 0x8 y_structures[0].int_one 0x12 y_structures[0].int_two 0x16 y_structure[0].pointer 0x24 y_structures[1].int_one 0x28 y_structures[1].int_two 0x32 y_structure[1].pointer ... so there must 6 padding bytes. not necessary on 32 bit machines, because there pointer have 4 byte.
Comments
Post a Comment