typeof and bitfields
Andreas Schwab
schwab@suse.de
Fri Jan 14 18:27:00 GMT 2005
"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."
More information about the Gcc
mailing list