delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/01/16/06:01:39

Date: Wed, 14 Jan 98 16:14:35 PST
From: Noam Rotem <nrotem AT johnbryce DOT co DOT il>
Subject: Re: Bit fields in djgpp: +1 turned into -1
To: Anthony DOT Appleyard AT umist DOT ac DOT uk
Cc: djgpp AT delorie DOT com
Message-Id: <Chameleon.980114163428.nrotem@netvision.netvision>
Mime-Version: 1.0

>  A field declared as `int x:1;' has only one bit. As that field is in a
>signed mode, that bit is the sign bit, and if that bit is set, the value is
>treated as -1. If you want a field `int x:N;' to contain values from 0 to
>pow(2,N)-1, you must declare the field as `unsigned int x:N;'.
>  If a program contains the words `unsigned' and `register' a lot, I find 
it
>useful to put these lines at the top of the program file:-
>#define uns unsigned
>#define reg register

Thanks. (So logical, so wise... and yet - never occurred to me...).

Anyway, about your final remark there: isn't it better to use:

   typedef unsigned int uns 

rather than :

   #define uns unsigned

?? This form is checked by the compiler (and not precompiled), and sounds a 
better way to do the same. 

---------------------------------------------
Noam Rotem
John Bryce Training Centre
Tel Aviv, Israel.
03-7535803
=============================================
1. Take upon yourself an impossible mission.
2. Accomplish the mission.
3. Go back to step 1.

It's the only sane answer to modern life.

---
14/01/98
16:14:35

- Raw text -


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