From: scottc AT net-community DOT com (Scott Christley) Subject: Re: one point (Was [Re: FW: Re: wxwin port]) 18 Nov 1996 16:48:26 -0800 Sender: daemon AT cygnus DOT com Approved: cygnus DOT gnu-win32 AT cygnus DOT com Distribution: cygnus Message-ID: <199611181259.EAA32405.cygnus.gnu-win32@stetson.net-community.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-Sender: scottc AT net-community DOT com X-Mailer: Windows Eudora Light Version 1.5.2 Original-To: Keith Gary Boyce Original-Cc: gnu-win32 AT cygnus DOT com Original-Sender: owner-gnu-win32 AT cygnus DOT com 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 >> > >> > 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".