From: Vineet Soni <vsoni@tilera.com>
To: Cedric Roux <cedric.roux@acri-st.fr>
Cc: gcc-help@gcc.gnu.org
Subject: Re: long bit-fields with g++ 4.4.1
Date: Fri, 12 Mar 2010 16:17:00 -0000 [thread overview]
Message-ID: <4B9A6414.10101@tilera.com> (raw)
In-Reply-To: <4B9A0984.2020209@acri-st.fr>
Cedric Roux wrote:
>
> If that is what you refer to:
> 3 An rvalue for an integral bit-field (_class.bit_) can be converted to
> an rvalue of type int if int can represent all the values of the bit-
> field; otherwise, it can be converted to unsigned int if unsigned int
> can represent all the values of the bit-field. If the bit-field is
> larger yet, no integral promotion applies to it. If the bit-field has
> an enumerated type, it is treated as any other value of that type for
> promotion purposes.
> (found on the internet, I don't have the standard)
>
> we can understand that "t" may be promoted to "int" (which is 32b) because
> it occupies 16 bits. And the << arithmetic operator asks for the
> promotion.
>
> Maybe that's why you have 0.
> Maybe that's the way it has to be and gcc 4.0.2 was wrong.
Your citation applies, but my interpretation differs:
In C++ a bit-field has the declared type; the number of bits is not part of its
type [1][2]. The C++ integer promotion rules apply [your citation above]; in
particular the clause: "If the bit-field is larger yet, no integral promotion
applies to it". A bit-field expression of declared type long is unchanged by
integer promotions, since (the number of bits in the bit-field being irrelevant)
long is larger than int and unsigned int. So the expected output is:
100000000 200000000 100000000
8000 100000000 8000
[1] ISO/IEC 14882-1998 [class.bit] The bit-field attribute is not part of the
type of the class member.
[2] C++ Standard Core Language Issue #303
(http://www.open-std.org/JTC1/SC22/WG21/docs/cwg_closed.html#303)
>
> Note that doing:
> printf("%lx %lx %lx\n", (T)t.f, (T)((unsigned long)t.f << 17),
> (T)(((unsigned long)t.f << 17) >> 17));
> prints what you wait (not 0)
> (with a g++ 4.3.2, not even 4.4.1)
Yes, we can cast, but the question is what is the correct behavior in the absence of
a cast. I don't want to find all the places in existing code where a cast might
be necessary, if 4.4.1 behavior is a bug.
-- Vineet
next prev parent reply other threads:[~2010-03-12 15:56 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-11 20:31 Vineet Soni
2010-03-12 13:49 ` Cedric Roux
2010-03-12 16:17 ` Vineet Soni [this message]
2010-03-16 14:56 ` Ian Lance Taylor
2010-03-16 18:17 ` Vineet Soni
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=4B9A6414.10101@tilera.com \
--to=vsoni@tilera.com \
--cc=cedric.roux@acri-st.fr \
--cc=gcc-help@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).