Mail Archives: djgpp/1997/06/17/10:11:18
News Administrator wrote:
>
> Dear DJGPP users!
>
> Recently I came across something weird:
> I have two structs:
> struct s1 { char c1; char c2; short s};
> struct s2 { char c1; short s; char c2};
>
> A call to sizeof will return 4 for s1 and 6 (!) for s2.
> It seems like the size of the chars in s2 gets increased to 2.
>
> Does anybody know of a compiler option or some other way to get DJGPP
> to use 1 byte chars regardless of their context?
You should examine the FAQ (v2/faq210b.zip), chapter 22.9, for a
detailed answer to this question. But in general, any 32-bit compiler
will align variables for maximum efficiency in memory access. This
sometimes means that struct members get padded to make them "line up" in
memory correctly.
You can use the gcc __attribute__ extension to turn off struct
alignment, or use the less-recommended #pragma pack(1)...#pragma pack()
solution.
--
---------------------------------------------------------------------
| John M. Aldrich, aka Fighteer I | mailto:fighteer AT cs DOT com |
| * Proud user of DJGPP! * | http://www.cs.com/fighteer |
| ObJoke: If Bill Gates were a robber, not only would he |
| shoot you, but he'd send you a bill for the bullets. |
---------------------------------------------------------------------
- Raw text -