Hi, I'm reading the header from bitmaps. When I add up everything in a struct I've made, it comes out to 54 bytes. When I do a sizeof(BHeader), it says it's 56 bytes. It adds two null bytes after the B and the M when I save a header to a file. It's very weird. Please help.

Here's my struct:

typedef struct
{
   unsigned char B;
   unsigned char M;
   unsigned int Size;
   short Reserved1;
   short Reserved2;
   unsigned int Offset;

   unsigned int HeaderSize;
   unsigned int Width;
   unsigned int Height;
   unsigned short Planes;
   unsigned short Bits;
   unsigned int Compression;
   unsigned int ImageSize;
   int XPixelsPerMeter;
   int YPixelsPerMeter;
   unsigned int ColorsInPalette;
   unsigned int ColorImportant;
} BHeader;

The compiler is aligning the struct elements on word (4byte) boundaries, thus the two empty bytes between your char's and the next element.

You might look up what the pack pragma will do for you, or other compiler options.

commented: The old favourites are the best :) +29

Thanks! It works now.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.