0

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;
2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by TheBeast32
Featured Replies
  • 1
    vmanes 1,165   7 Years Ago

    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. Read More

1

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.

Comments
The old favourites are the best :)
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.