www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/04/14/08:15:47

From: "Marp" <Marp AT 0 DOT 0 DOT 0 DOT 0>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: BOOL as char/int
Date: Tue, 13 Apr 1999 23:48:28 -0400
Organization: Netcom
Lines: 22
Message-ID: <7f136b$351@dfw-ixnews6.ix.netcom.com>
References: <7ev4na$49a$1 AT lola DOT ctv DOT es>
NNTP-Posting-Host: prn-nj1-25.ix.netcom.com
X-NETCOM-Date: Tue Apr 13 10:48:27 PM CDT 1999
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2014.211
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2014.211
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Rafael García <rafael AT geninfor DOT com> wrote in message
news:7ev4na$49a$1 AT lola DOT ctv DOT es...
> It fails with BOOL as char, but works as int
> Can someone explain this reasonably?
> It works well with Borland
> I have been using this typedef for years and it seems standard, robust,
> good, pretty, simple, near-machine, fast, compact...
> It seems gods of chaos are conquering the world of computing

After doing some experimentation, I think I have found the answer. When the
function isupper returns "true" it is returning the number 512. The ansi
spec says that isupper may return any non-zero int value when it returns
"true" and zero when "false." The problem here is that char datatype is 8
bits and can only hold values between 0 and 255 (unsigned). If you go over
255, it rolls over to zero, for example 255 + 1 = 0 as far as char is
concerned, but is 256 with int. Since 512 is twice as much as 256, char
rolls over to zero twice and BOOL find hold zero. So when you test the value
with BOOL as type char, you get zero, and with type int, you get 512, or
"true". Hope this helps you understand better.


- Raw text -


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