Mail Archives: djgpp/1998/04/18/13:16:46
From: | "J.R. Wessels" <wessels AT megavision DOT com>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Re: Struct optimizing by compiler
|
Date: | Sat, 18 Apr 1998 10:51:28 -0600
|
Organization: | Kimball High School
|
Lines: | 34
|
Message-ID: | <3538DA10.124F11CB@megavision.com>
|
References: | <01bd6ad8$16320920$151601bf AT cb001687>
|
NNTP-Posting-Host: | kim02.megavision.com
|
Mime-Version: | 1.0
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
I think that the compiler allocates four bytes for X because of alignment. If
you organize the structure to declare the largest members first and smallest
last, it should fix your problem. Another source of your problem may be that
the default alignment is set at 4 bytes.
Jasper van Woudenberg wrote:
> Hi,
>
> When i try to define a structure, it seems that the compiler sometimes
> optimizes the variables to start at a 'long' address. for example:
>
> struct X { short X, // (can) reserve 4 bytes for X, to get Y at
> a 'long' address
> long Y,
> short Z };
>
> Sometimes interrupt routines return pointers to data structures in memory,
> and when i copy that data into a structure like the above, the data is
> corrupted, because X uses 4 bytes in stead of 2 bytes. How can i make the
> compiler _always_ reserve 2 bytes for a short, 4 bytes for a long, etc.?
>
> Jasper.
--
J.R. Wessels
wessels AT megavision DOT com
http://www.geocities.com/SiliconValley/Horizon/7865
- Raw text -