i have written this structure:
struct bmpheader {
unsigned char magic[2];
unsigned int fsize;
unsigned int unused;
unsigned int pixdata_offset;
unsigned int headersize;
unsigned int width;
unsigned int height;
unsigned short planes_color;
unsigned short bpp;
unsigned int compression;
unsigned int sizeofpix;
unsigned int resolutionx;
unsigned int resolutiony;
unsigned int colors;
unsigned int imp_colors;
};
And i have a problem with sizeof function. When im counting on my fingers, its every time 54 bytes for me. sizeof function gives me every time 56. Why? The problem is with unsigned char array, when i remove magic[2] array, sizeof is 52? sizeof(header.magic) is shown as 2. As far i know unsigned char is 1-byte type?
Thanks in advance for responses.
marcin
Because an int
(on your machine) must be, or is more efficient when, placed on a 4-byte address. The compiler will insert two bytes of padding after the char array.