C++ The compiler is changing the alignment of my structures. How can I prevent this?
问题 I am writing some code to read bitmap files. Here is the struct I am using to read the bitmap header. See also: https://msdn.microsoft.com/en-us/library/windows/desktop/dd183374(v=vs.85).aspx struct BITMAPFILEHEADER { WORD bfType; // 2 DWORD bfSize; // 6 WORD bfReserved1; // 8 WORD bfReserved2; // 10 DWORD bfOffBits; // 14 }; // should add to 14 bytes If I put the following code in my main function: std::cout << "BITMAPFILEHEADER: " << sizeof(BITMAPFILEHEADER) << std::endl; the program prints