This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: typeof and bitfields


"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."


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]