Mail Archives: djgpp/1998/06/08/18:47:45
From: | "John M. Aldrich" <fighteer AT cs DOT com>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Re: Sizeof messed up
|
Date: | Mon, 08 Jun 1998 18:44:08 -0400
|
Organization: | Two pounds of chaos and a pinch of salt.
|
Lines: | 35
|
Message-ID: | <357C6938.C652AD69@cs.com>
|
References: | <357c0fc1 DOT 0 AT news DOT myna DOT com>
|
NNTP-Posting-Host: | ppp135.cs.net
|
Mime-Version: | 1.0
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Vimal N. Lad / Gautam N. Lad wrote:
>
> Hi,
> I have DJGPP v2.7.2 (I think) and Allegro v3.0. I am trying to make
> my own TGA reader (I know Allegro already has it, but this is for
> a Windows program and I am using DJGPP & Allegro to test
> and display the format).
There is no DJGPP 2.7.2; it's DJGPP 2.01, with whatever version of gcc
you desire to use (2.7.2, 2.7.2.1, 2.8.0, 2.8.1). It's not a big deal,
but it helps to be specific.
> For some odd reason, the sizeof function returns the wrong size.
> I have a structure, which is exactly 18 bytes long. When I call
> sizeof(TGAHEAD); (I am trying to read the header of a .TGA file),
> it says the header is 20 bytes long. I have the correct structure
> for the TGA format and in another compiler, Turbo C++ v1.0, it
> returns the correct size wich is 18 bytes.
This is because, in a 32-bit environment, structure members (and
structures themselves) often have extra bytes added on to the end so
that they are aligned on 32-bit boundaries in memory. This practice can
as much as double the speed of accessing them.
Chapter 22.9 of the DJGPP FAQ covers struct size in greater detail and
points you to the gcc __attribute__ extension which you can use to pack
structs down to their minimum size.
--
---------------------------------------------------------------------
| John M. Aldrich | "If 'everybody knows' such-and-such, |
| aka Fighteer I | then it ain't so, by at least ten |
| mailto:fighteer AT cs DOT com | thousand to one." |
| http://www.cs.com/fighteer | - Lazarus Long |
---------------------------------------------------------------------
- Raw text -