Subject: Re: one point (Was [Re: FW: Re: wxwin port])
From: [email-masked] ("Mike Smith")

19 Nov 1996 03:24:28 -0800
Sender: [email-masked]
Approved: [email-masked]
Distribution: cygnus
Message-ID: <9611191007.AA05896.cygnus.gnu-win32@symsun10>
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7BIT
Comments: Authenticated sender is <mps@symsun10>
Original-To: Scott Christley <[email-masked]>
Original-Cc: [email-masked]
X-Mailer: Pegasus Mail for Win32 (v2.42a)
Original-Sender: [email-masked]

I think the problem here (without actually comiling a test program) 
is that GNU is trying to align the first DWORD field onto a 4-byte 
offset.  It therefore adds two bytes after the bfType field. It needs 
to add no further padding after this because the following fields are 
on the correct alignment.

> Date:          Mon, 18 Nov 1996 04:59:56 -0800
> To:            Keith Gary Boyce <[email-masked]>
> From:          Scott Christley <[email-masked]>
> Subject:       Re: one point (Was [Re: FW: Re: wxwin port])
> Cc:            [email-masked]

> 
> 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 <[email-masked]>
> >> > 
> >> > 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
> >"[email-masked]" with one line of text: "help".
> >
> 
> -
> For help on using this list, send a message to
> "[email-masked]" with one line of text: "help".
> 
> 

--------------------------------------------------------------------
Mike Smith                             Symbionics Communications Ltd
EMAIL:  [email-masked]           St John's Innovation Park
                                       Cowley Road, Cambridge
TEL:    +44 1223 421 025               CB4 4WS
FAX:    +44 1223 421 031               UK
--------------------------------------------------------------------
-
For help on using this list, send a message to
"[email-masked]" with one line of text: "help".