Computer Chess Club Archives


Search

Terms

Messages

Subject: bool versus BOOL in C++

Author: Gerd Isenberg

Date: 03:50:59 09/26/03


Hi All,

in C++ we have the boolean type "bool" with the value range true/false.
I'm not sure about ANSI-C.

Due to some C-related "portability" problems and possible performance drawbacks
due sizeof(bool) == 1 implies partial register handling or zero extending to
native word lenght, you find in most MS-sources an "own" boolean type BOOL:

typedef int BOOL; // e.g. WINDEF.H

This own BOOL type is of course not "typesafe" as bool, as you may assign any
"int" expressions to it. With BOOL one should interprete zero as FALSE and any
other value as TRUE. Due to this ambiguity, comparing BOOL-expressions with TRUE
may be erroneous, so better compare with != FALSE.

See also this bugreport related to this issue:

http://www.codeproject.com/buglist/virtualboolbug.asp

Actually i have some "disputes" with colleagues obout it.
I found bool better for didactical reasons,
but stay with BOOL for pragmatical reasons.

A few questions:

Is sizeof(bool) == 1 per definition,
or is it compiler implementation depending?

Is there any conditional preprocessor directive to ask whether a user defined
type is already typedefined, similar to #ifdef?

What is your opinion / experience with bool versus BOOL?

Thanks in advance for your suggestions,
Gerd





This page took 0.01 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.