This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: EGCS 2.91.66 Bug: sizeof() + struct problem (char == and != int)
- To: burnus at gmx dot de
- Subject: Re: EGCS 2.91.66 Bug: sizeof() + struct problem (char == and != int)
- From: "Martin v. Loewis" <martin at mira dot isdn dot cs dot tu-berlin dot de>
- Date: Sat, 18 Sep 1999 13:12:47 +0200
- CC: egcs-bugs at egcs dot cygnus dot com
- References: <37E2E00B.136BE41@gmx.de>
> I get this output:
> ---------------------------------------------------------------------------
> sizeof=12
> sizeof=12
> 1 -- 2 -- 4
> ---------------------------------------------------------------------------
> whereas I had expected it to be 10 and 7 !!
Thanks for your bug report. I fail to see the bug in it, though - you
did not say *why* you expected these results, and why you think that
any other results are wrong.
Anyway, there is a good reason for it: The compiler aligns fields
according to their "alignment requirements". You can find out more
about alignment in a number of documents:
- the ISO C standard,
- documentation about the Intel 386 processor,
- definition of the Unix ABI on Intel, and
- the GCC documentation.
As a result of alignment, the compiler inserts "padding" between
fields. *Not* doing so would be a bug, as it would break binary
compatibility.
Hope this helps,
Martin