I have VC++ 2012 and noticed that if have something like
struct mystruct{
char a[100];
__int64 b; };
then sizeof(mystruct) would yield 112.
Why is this?
I have VC++ 2012 and noticed that if have something like
struct mystruct{
char a[100];
__int64 b; };
then sizeof(mystruct) would yield 112.
Why is this?
Padding has to be added. Consider:
mystruct *a = (mystrct *) malloc (16 * sizeof (mystruct));
If there was no padding, some of the 64-bit integers wouldn't be aligned.
If you need data in a particular binary format, you must write code to put that data in that binary format. Don't try to do it by accident or by magic. Write code that produces precisely the bytes you want in the file.
Why is this? Short answer, memory alignment.
The long answer is here: http://www.catb.org/esr/structure-packing/