delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/01/14/06:14:30

Date: Wed, 14 Jan 1998 13:14:23 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Nate Eldredge <eldredge AT ap DOT net>
cc: Noam Rotem <nrotem AT johnbryce DOT co DOT il>, djgpp AT delorie DOT com
Subject: Re: Bit fields in djgpp
In-Reply-To: <199801140201.SAA28635@adit.ap.net>
Message-ID: <Pine.SUN.3.91.980114131317.8730G-100000@is>
MIME-Version: 1.0

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019