Message-ID: From: George Kinney To: "'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) Content-Type: text/plain 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.