This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: typeof and bitfields
- From: Andreas Schwab <schwab at suse dot de>
- To: "Dave Korn" <dave dot korn at artimi dot com>
- Cc: "'Ian Lance Taylor'" <ian at airs dot com>,"'Neil Booth'" <neil at daikokuya dot co dot uk>,"'Matt Austern'" <austern at apple dot com>,"'Gabriel Dos Reis'" <gdr at integrable-solutions dot net>,<gcc at gcc dot gnu dot org>, "'Andrew Pinski'" <pinskia at physics dot uc dot edu>
- Date: Fri, 14 Jan 2005 17:36:14 +0100
- Subject: Re: typeof and bitfields
- References: <NUTMEGZfv4eqfxrCXIj00001066@NUTMEG.CAM.ARTIMI.COM>
"Dave Korn" <dave.korn@artimi.com> writes:
> While we're on the subject, I've always been curious what on earth the meaning
> of
>
> struct foo {
> int bar : 1;
> };
>
> could possibly mean.
Note that it is implementation defined, whether bit-fields of type int are
signed or unsigned.
> What are the range of values in a 1-bit signed int? Is that 1 bit the
> sign bit or the value field?
It's one sign bit and zero value bits.
> Can bar hold the values 0 and 1, or 0 and -1, or some other set?
Depends on the representation: with two's complement it's -1 and 0, with
sign/magnitude or one's complement it's 0 and -0.
> In a one bit field, the twos-complement operation degenerates into the
> identity - how can the concept of signed arithmetic retain any coherency
> in this case?
It's no different from -INT_MIN: you get an overflow.
Andreas.
--
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."