Change of type alignment and the consequences

When porting software one of the task a developer faces is to change types’ sizes and rules of their alignments.

Once my attention was attracted by a message in RSDN forum:

Today I have faced a problem in Linux. There is a data structure consisting of several fields: 64-bit double, 8 unsigned char and one 32-bit int. Altogether it is 20 bytes (8 + 8*1 + 4). On 32-bit systems sizeof is 20 bytes and everything is OK. But on the 64-bit Linux sizeof returns 24 bytes. That is, an alignment at the 64-bit border takes place.

Continue reading