Mail Archives: djgpp/2003/01/08/07:30:02
Joel Saunders (jbs30000 AT aol DOT com) wrote:
: In writting a simple bmp loader, I'm having problems with the struct for
: the bmp header. Even with __attribute__((__packed__)) after each item:
: struct BMP_Header {
: unsigned int BM __attribute__((__packed__));
4 bytes.
: unsigned long File_Size __attribute__((__packed__));
4 bytes.
: unsigned int R_1 __attribute__((__packed__)); // Reserved 1
4 bytes.
: unsigned int R_2 __attribute__((__packed__)); // Reserved 2
4 bytes.
: unsigned long BMP_Offset __attribute__((__packed__));
4 bytes.
...
: }image;
: I had to do this to use the header information:
: unsigned char image[54];
: #define image_BM ((int *)&image[0])[0]
2 bytes.
: #define image_File_Size ((long *)&image[2])[0]
4 bytes.
: #define image_R_1 ((int *)&image[6])[0]
2 bytes.
: #define image_R_2 ((int *)&image[8])[0]
2 bytes.
: #define image_BMP_Offset ((long *)&image[10])[0]
4 bytes.
: #define image_Header_Info ((long *)&image[14])[0]
Perhaps you see the problem now?
You forgot to check what sizeof(int) equals.
Then a question of my own; is there any advantage using
"((long *)&image[2])[0]" vs. "*((long *)&image[2])"?
Right,
MartinS
- Raw text -