We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
what do you expect the result to be?
typedef struct { signed int bit:1; } T_oddity; T_oddity oddity; int foobar( int arg ) { oddity.bit = arg; return oddity.bit; } void foochocolate ( void ) { // stuff foobar ( -1 ); // stuff }
I looked through C99, and it doesn't seem to cover this particular case. I guess you can consider it implementation-defined.
I can't see why the standard should need to contain any special paragraph. The special is if the architecture have two-complement numbers or not. Scaling two-complement numbers all the way to a single bit shouldn't need standard coverage.
A signed two-complement number of only one bit is per definition -1 or 0. A 2-bit number would be -2..1. A 3-bit number would be -4..3.
This is a very, very common mistake when people only writes "int" as type for their bit fields. Or maybe "char" if the compiler have signed characters. Then they try to figure out why if (s.mybit == 1) always fails.
thanks. i've never seen the mistake before. you are obviously a very wise old owl. that is a compliment ;)
if i ever see it i will think of you.