Mail Archives: djgpp/1998/01/14/06:14:30
On Tue, 13 Jan 1998, Nate Eldredge wrote:
> Since you declare your bitfields as `int', they are signed. Typically a
> two's-complement signed number with all 1's set is the number -1, and
> apparently this is also true for one-bit values. Solution: Declare the
> bitfields as `unsigned'.
I'm not sure this solution is indeed required. I think what Noam
reported was due to the effect of `printf', and the actual value
stored inside the variable was correct.
You should never forget that `printf' doesn't know about any data
types except the basic ones (ints, doubles, long ints, etc.);
everything else is converted to one of the basic types, and *then*
printed. A single-bit field with a value of 1 is probably
sign-extended to -1 by the call to `printf'. Examining the bits under
a debugger would probably clarify this.
- Raw text -