M
Mike C#
Hi all,
I was having a discussion with a co-worker about alignment of structures in
memory, and we came across a question. We have a struct like the following:
struct Car
{
unsigned char VIN[17];
unsigned char Make[26];
unsigned char Model[26];
unsigned short Year;
...
}
The sizeof(struct) is 916 bytes. If we want to compile and run this code on
64-bit Windows do we need to add a 4-byte array to the struct to make it
align on an 8-byte boundary? Or will the compiler handle that for us?
Also, are there any other reasons we might want to 'force' it to line up on
an 8-byte boundary? For instance, if we want to call the function from
other languages, etc.?
Thanks
I was having a discussion with a co-worker about alignment of structures in
memory, and we came across a question. We have a struct like the following:
struct Car
{
unsigned char VIN[17];
unsigned char Make[26];
unsigned char Model[26];
unsigned short Year;
...
}
The sizeof(struct) is 916 bytes. If we want to compile and run this code on
64-bit Windows do we need to add a 4-byte array to the struct to make it
align on an 8-byte boundary? Or will the compiler handle that for us?
Also, are there any other reasons we might want to 'force' it to line up on
an 8-byte boundary? For instance, if we want to call the function from
other languages, etc.?
Thanks