The size of the following struct should be 14 bytes. It appears to be 16 bytes. When I write it to a binary file, two bytes seem to be inserted after the first two bytes. The two erroneous bytes have the hex values: cc cc. The first four bytes of the struct when filled out appropriately are: 42 4D CC CC
This is the smallest amount of code that I could reproduce the problem
unsigned short bfType;// = 19778 = 'BM'
unsigned int bfSize;// = size of file
unsigned short bfReserved1, bfReserved2;// = 0;
unsigned int bfOffBits;// = 54;
cout<<"\n Size of ushort: " << sizeof(unsigned short);
cout<<"\n Size of uint: " << sizeof (unsigned int);
cout<<"\n Expected size of struct: " << sizeof(unsigned short) * 3 + sizeof(unsigned int) * 2;
cout<<"\n Size of bfHeader: " << sizeof(bfHeader);
This was done on VC++ 2008 express. Why is this struct 16 bytes in size?
Size of ushort: 2
Size of uint: 4
Expected size of struct: 14
Size of bfHeader: 16