Subject: Re: one point (Was [Re: FW: Re: wxwin port])
From: [email-masked] (Scott Christley)

18 Nov 1996 16:48:26 -0800
Sender: [email-masked]
Approved: [email-masked]
Distribution: cygnus
Message-ID: <[email-masked]>
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
X-Sender: [email-masked]
X-Mailer: Windows Eudora Light Version 1.5.2
Original-To: Keith Gary Boyce <[email-masked]>
Original-Cc: [email-masked]
Original-Sender: [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".