www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/10/07/18:31:51

Message-ID: <DB85AFBE7C0DD311BF260004ACB80BFCEC35@nex_server.nextransport.com>
From: George Kinney <GKinney AT nextransport DOT com>
To: "'djgpp AT delorie DOT com'" <djgpp AT delorie DOT com>
Subject: RE: What's this? A bug?
Date: Thu, 7 Oct 1999 15:10:26 -0400
MIME-Version: 1.0
X-Mailer: Internet Mail Service (5.5.2448.0)
Reply-To: djgpp AT delorie DOT com

>Here is the code which counts the number of nonzero bits in int value.
>It works fine until you enter negativ value, e.g. when i enter value -1
>it counts 32 nonzero bits (although we all know that int has only 16
bits)!?
>The same code compiled under the BC++ 3.1 acts normal (under 16 bits
counted
>for each negative value).

BC++ 3.1 is a 16bit compiler, meaning ints are 16bits. (TurboCv1 was 8bit,
thus 8bit ints)
DJGPP is a 32bit compiler, meaning ints are 32bits. The size of an int is
*not*, I repeat
*NOT* always the same between compilers and platforms. 

In other words, you're comparing apples to oranges. DJGPP is acting entirely
normal
also. It has 32bit ints, therefore for it counts 32 bits on for -1. The same
program under
TurboC v1 would say there were 8 bits on. And so on, and so on, and so on...

With DJGPP, if you must use 16bit value, use short.

- Raw text -


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