This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
#pragma pack vs. zero-width bitfields
- From: Mark Mitchell <mark at codesourcery dot com>
- To: gcc at gcc dot gnu dot org
- Date: Mon, 19 Dec 2005 18:33:33 -0800
- Subject: #pragma pack vs. zero-width bitfields
PR 22275 is about a change in the structure layout used by GCC when
#pragma pack is mixed with zero-width bitfields. In particular, in GCC
3.3 and earlier, zero-width bitfields still forced the next element to
be placed on an alignment boundary, just as they do in unpacked
structures. In GCC 3.4 and later, zero-width bitfields no longer have
this effect, when used within a structure.
I believe the older behavior was better. The entire purpose for a
zero-width bitfield is to make an alignment request. So, we should
assume that if the user wrote that, even within the scope of #pragma
pack, they had a reason for doing so. #pragma pack should pack the
things that are not explicitly aligned, but it should no more pack the
field following a zero-width bitfield than it should a field that has an
explicit alignment attribute.
As a result, I believe that we should change the behavior back in GCC
4.1. We should not change GCC 3.4.x or GCC 4.0.x because that would be
an ABI change within a single release branch.
I know this was discussed previously to some extent, but I'm not sure if
we reached consensus. I'm going to interpret silence as assent if
nobody objects within a few days. So, any disagreements?
Thanks,
--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
(650) 331-3385 x713