TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: Roger Scudder
from: Bob Stout
date: 2003-09-07 20:23:44
subject: RE: Pointers

From: rbs{at}snippets.org
To: c_echo{at}yahoogroups.com

On Sun, 7 Sep 2003, Roger Scudder wrote:

> >> BS> Indeed, but how is it in C, with integers, I've
defined TRUE as 1
> >> BS> and FALSE as 0
>
> >> I think a better definition would be to #define FALSE 0 and TRUE
> !FALSE -
> >> in other words,  nonzero.
>
> Conceptually, it makes sense...  But when the preprocessor gets through
> with it FALSE is still just a 0
>
> There is a macro in sniptype.h
>
> #define TOBOOL(x)		(!(!(x)))
>
> That little macro says it all.

I wish I could take credit for it, but that little gem cam from long-
forgotten C_Echo source. Still both the 1989 and 1999 standards define an
boolean true to evaluate to specifically to 1, although as a practical
matter, a strong argument could be made for simply testing all results to
zero. The TOBOOL() macro simply coerces its argument is to either 0 or 1
in compliance with the standard.

I included it in SNIPTYPE.H as much for its cleverness as for any specific
utility. It can, however, come in handy in excessively pedantic code.
However, any decent optimizer will rewrite that sort of code anyway...

-------------------------------------------------------------
Consulting: http://www.MicroFirm.biz/
Web graphics development: http://Image-Magicians.com/
Software archives: http://snippets.org/snippets/
Audio and loudspeaker design:
  http://LDSG.snippets.org/
  http://www.diyspeakers.net/

--- SoupGate-Win32 v1.05
* Origin: rbs{at}snippets.org (2:292/516.666)
SEEN-BY: 633/267 270
@PATH: 292/516 854 140/1 106/2000 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.