public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: Nathan Sidwell <nathan@codesourcery.com>
To: nathan@gcc.gnu.org
Cc: gcc-prs@gcc.gnu.org,
Subject: Re: c++/7432: Changed bitfield allocation strategy in g++ 3.1.1
Date: Mon, 29 Jul 2002 10:56:00 -0000	[thread overview]
Message-ID: <20020729175600.8484.qmail@sources.redhat.com> (raw)

The following reply was made to PR c++/7432; it has been noted by GNATS.

From: Nathan Sidwell <nathan@codesourcery.com>
To: grigory@stl.sarov.ru
Cc: gcc-gnats@gcc.gnu.org
Subject: Re: c++/7432: Changed bitfield allocation strategy in g++ 3.1.1
Date: Mon, 29 Jul 2002 18:50:35 +0100

 grigory@stl.sarov.ru wrote:
 
 >   struct C {
 >     char c;
 >     int i : 67;
 >     char d;
 >   };
 > 
 > This is what been offered by GNU compiler for a long time. GCC 3.1.1
 > compiler gives another size of the structure (24 bytes).
 It turns out that gcc and g++ disagreed about this. the 3.1.1
 behaviour is the same for both (which is good).
 
 > I do not see any reason to enlarge space taken by the structure C,
 The behaviour should be the same for C and C++ (gory details to follow)
 
 > moreover I do not see any ABI acknowledgment for this.
 No, sorry - we had not realized this change had occurred.
 
 Intel's i86 C ABI allocates long longs in structures on a four byte
 boundary, even though the naked alignment of a long long is 8 bytes.
 Thus for the non-bitfield case
 	struct C {
 		char c;
 		long long i;
 		char e;
 	};
 will allocate i at offset 4 and e at offset 12, the size will be 16
 and the overall alignment will be 4. However, when we make i a 64 bit
 bitfield,
 	struct C {
 		char c;
 		long long i : 64;
 		char e;
 	};
 the behaviour is different. PCC_BITFIELD_TYPE_MATTERS comes into play
 and does not allow a bitfield of type T to straddle the natural
 alignment of T. So i is placed at offset 8.
 
 for your case
 	struct C {
 		char c;
 		int i : 67;
 		char e;
 	};
 as int has 32 bits, we find the largest integral type which has <= 67
 bits, this is long long. The bitfield is treated as a long long
 bitfield of 67 bits, that is 64 bits of accessible data and 3 bits
 of unreachable padding.
 
 G++'s behaviour now matches that of gcc - so PoD layouts are compatible.
 
 nathan
 
 -- 
 Dr Nathan Sidwell   ::   http://www.codesourcery.com   ::   CodeSourcery LLC
          'But that's a lie.' - 'Yes it is. What's your point?'
 nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org


             reply	other threads:[~2002-07-29 17:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-29 10:56 Nathan Sidwell [this message]
  -- strict thread matches above, loose matches on Subject: below --
2002-07-29 10:52 nathan
2002-07-29  8:50 nathan
2002-07-29  5:26 grigory

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20020729175600.8484.qmail@sources.redhat.com \
    --to=nathan@codesourcery.com \
    --cc=gcc-prs@gcc.gnu.org \
    --cc=nathan@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).