Mail Archives: cygwin/1996/11/18/16:48:26
I've run across this problem with some other structures. It appears that
GCC will automatically align the size of some variables in order to eek out
more performance. A WORD, which is an unsigned short, should be 16 bits but
GCC will pad it out to a full 32 bits which is presumably more efficient to
pass. I've noticed this in structures which have an odd number of WORD
variables as the BITMAPFILEHEADER structure below. When there is an even
number of WORD variables then GCC appears to pack both into 32 bits.
The way I would solve the problem is such:
struct tagBITMAPFILEHEADER {
WORD bfType;
DWORD bfSize;
WORD bfReserved1;
WORD bfReserved2;
DWORD bfOffBits;
} __attribute__ ((packed));
typedef struct tagBITMAPFILEHEADER BITMAPFILEHEADER;
typedef struct tagBITMAPFILEHEADER FAR *BITMAPFILEHEADER;
typedef struct tagBITMAPFILEHEADER *PBITMAPFILEHEADER;
You cannot use the packed attribute on a typedef because a typedef is just a
name declaration. Review the chapter on the GCC extensions to the C
language in the GCC documentation about the packed attribute.
Scott
ps: I would appreciate if anybody discovers such structure packing problems
to please forward them to me so that they will get fixed in the windows32api
library.
>> > From: Keith Gary Boyce <garp AT opustel DOT com>
>> >
>> > Does anyone have any input on why 16 bytes from gnu-win32 and
>> > 14 for other compiler
>> >
>> > >typedef struct tagBITMAPFILEHEADER {
>> > > WORD bfType;
>> > > DWORD bfSize;
>> > > WORD bfReserved1;
>> > > WORD bfReserved2;
>> > > DWORD bfOffBits;
>> > >} BITMAPFILEHEADER, FAR *LPBITMAPFILEHEADER, *PBITMAPFILEHEADER;
>
>[[ ... other quotations deleted ... ]]
>
>-
>For help on using this list, send a message to
>"gnu-win32-request AT cygnus DOT com" with one line of text: "help".
>
-
For help on using this list, send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".
- Raw text -