delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1996/11/19/03:24:28

From: mps AT symbionics DOT co DOT uk ("Mike Smith")
Subject: Re: one point (Was [Re: FW: Re: wxwin port])
19 Nov 1996 03:24:28 -0800 :
Sender: daemon AT cygnus DOT com
Approved: cygnus DOT gnu-win32 AT cygnus DOT com
Distribution: cygnus
Message-ID: <9611191007.AA05896.cygnus.gnu-win32@symsun10>
Mime-Version: 1.0
Comments: Authenticated sender is <mps AT symsun10>
Original-To: Scott Christley <scottc AT net-community DOT com>
Original-Cc: gnu-win32 AT cygnus DOT com
X-Mailer: Pegasus Mail for Win32 (v2.42a)
Original-Sender: owner-gnu-win32 AT cygnus DOT com

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 <garp AT opustel DOT com>
> From:          Scott Christley <scottc AT net-community DOT com>
> Subject:       Re: one point (Was [Re: FW: Re: wxwin port])
> Cc:            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 <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".
> 
> 

--------------------------------------------------------------------
Mike Smith                             Symbionics Communications Ltd
EMAIL:  mps AT symbionics DOT co DOT uk           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
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019