Subject: Re: FW: Re: wxwin port
From: [email-masked] (Keith Gary Boyce)

10 Nov 1996 15:36:22 -0800
Sender: [email-masked]
Approved: [email-masked]
Distribution: cygnus
Message-ID: <[email-masked]>
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; CHARSET=US-ASCII
Original-To: Wayne Meissner <[email-masked]>, [email-masked]
X-PRIORITY: 3 (Normal)
X-Mailer: Chameleon 5.0, TCP/IP for Windows, NetManage Inc.
Original-Sender: [email-masked]

Will someone give me an answer in context....
How do I get sizeof(BITMAPFILEHEADER) to be 14 when structure is
as follows and with gnu-win32 sizeof(BITMAPFILEHEADER) is 16 when it 
should be 14?? Help would be greatly appreciated. 

(gdb) ptype BITMAPFILEHEADER
type = struct tagBITMAPFILEHEADER {
    short unsigned int bfType;
    unsigned int bfSize;
    short unsigned int bfReserved1;
    short unsigned int bfReserved2;
    unsigned int bfOffBits;
}

--- On Mon, 11 Nov 1996 00:25:54 +0000 (GMT)  Wayne Meissner 
<[email-masked]> wrote:
On Sun, 10 Nov 1996, Fabio Somenzi wrote:

> ->Does anyone have any input on why 16 bytes from gnu-win32 and
> ->14 for other compiler
> 
> I believe it's because gcc enforces alignment. The two extra bytes 
are
> not used. I've seen it done by other compilers as well.
> 
> In some applications alignment is important. For instance, a 16-byte
> structure can be aligned with the boundaries of the cache lines.
> 
> Alignment may also have to do with the memory manager (reducing the
> number of buckets,) but I'm not familiar with this aspect of gcc.
> 
> There may be a gcc option to enforce structure packing, but memory 
may
> fail me here.
There is __attribute__((packed))
e.g.
struct foo {
	char bar;	
	int foobar;
} __attribute__((packed));

That will pack the entire struct.
To pack just one member of the struct, put the __attribute__((packed))
after just that member.

There is also the command line option -fpack-struct, but that packs all
structs, including system ones, which may not be desirable.

I think there may be also #pragma pack, but I am not sure.

--wayne

-
For help on using this list, send a message to
"[email-masked]" with one line of text: "help".

-----------------End of Original Message-----------------

-------------------------------------
Name: Garry Boyce
E-mail: [email-masked] (Garry Boyce)
Date: 12/01/94
Time: 08:46:10

This message was sent by Chameleon 
-------------------------------------

-
For help on using this list, send a message to
"[email-masked]" with one line of text: "help".