delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/04/14/17:41:03

Sender: nate AT cartsys DOT com
Message-ID: <37150B30.9D4AB729@cartsys.com>
Date: Wed, 14 Apr 1999 14:40:00 -0700
From: Nate Eldredge <nate AT cartsys DOT com>
X-Mailer: Mozilla 4.08 [en] (X11; I; Linux 2.2.5 i586)
MIME-Version: 1.0
To: djgpp AT delorie DOT com
Subject: Re: BOOL as char/int
References: <m10X4gw-000S8ZC AT inti DOT gov DOT ar>
Reply-To: djgpp AT delorie DOT com

Salvador Eduardo Tropea (SET) wrote:
> 
> "Rafael Garcİa" <rafael AT geninfor DOT com> asked:
> 
> > 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
> 
> Nope, you must read the specs, this function returns:
> 
> 1) An int.
> 2) Nonzero if C is whitespace, else zero.
> 
> So it could return 0x100 and your char will be 0.
> You should use:
> 
> a= isspace(b) ? 1 : 0;

Or, if you like short but obfuscated code:

a = !!isspace(b);

-- 

Nate Eldredge
nate AT cartsys DOT com

- Raw text -


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