I am writing a bitmap loader and the byte count is not working correctly. I am currently using Xcode running a 64 bit unix executable.
The code:
typedef unsigned char BYTE;
typedef unsigned short WORD;
typedef unsigned int DWORD;
typedef struct {
WORD bfType;
DWORD bfSize;
WORD bfReserved1;
WORD bfReserved2;
DWORD bfOffbits;
} BITMAPFILEHEADER;
The sizeof function says the BITMAPFILEHEADER struct is 16 Bytes when it should be 14 Bytes. Any suggestions?
This might be because of structure alignment. Here take a look http://peeterjoot.wordpress.com/2009/11/11/c-structure-alignment-padding/
You can force the compiler not to align the structure by adding the attribute
__attribute__((__packed__))but as far as I know it only works in gcc.Here: