Date: Wed, 14 Jan 1998 13:14:23 +0200 (IST) From: Eli Zaretskii To: Nate Eldredge cc: Noam Rotem , djgpp AT delorie DOT com Subject: Re: Bit fields in djgpp In-Reply-To: <199801140201.SAA28635@adit.ap.net> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk 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.