This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: EGCS 2.91.66 Bug: sizeof() + struct problem (char == and != int)


> 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]