delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1996/11/10/15:36:22

From: garp AT opustel DOT com (Keith Gary Boyce)
Subject: Re: FW: Re: wxwin port
10 Nov 1996 15:36:22 -0800 :
Sender: daemon AT cygnus DOT com
Approved: cygnus DOT gnu-win32 AT cygnus DOT com
Distribution: cygnus
Message-ID: <Chameleon.847655588.garp.cygnus.gnu-win32@garp.worldnet.att.net>
Mime-Version: 1.0
Original-To: Wayne Meissner <w DOT meissner AT qut DOT edu DOT au>, gnu-win32 AT cygnus DOT com
X-PRIORITY: 3 (Normal)
X-Mailer: Chameleon 5.0, TCP/IP for Windows, NetManage Inc.
Original-Sender: owner-gnu-win32 AT cygnus DOT com

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 
<w DOT meissner AT qut DOT edu DOT au> 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
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".


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

-------------------------------------
Name: Garry Boyce
E-mail: garp AT opustel DOT opustel DOT com (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
"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