Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
BOOL Datatype
Message
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Title:
Miscellaneous
Thread ID:
00357504
Message ID:
00358521
Views:
16
IMO, this is like that because BOOL is meant as a logical type, not an int type. Since signed boolean values
really don't make sense, -1 is more a convenient chosen value than a logical (sic) choice. Anyway, -1 is -1 only if we
see it as a signed int value. If we see it as unsigned value, it depends on the length of the representation. So,
depending on this length, we would end up with different values for FALSE. Since C/C++ has a lot of implicit
conversions, -1 as FALSE could introduce subtle bugs when such conversions take place in unexpected places.
More, -1 may not be represented in the same way on different platforms and the conversions may not give the same
results on different platforms (yes, one of the "pleasures" of C/C++ :)). Since this value can be saved into files
that are transfered between platforms (or in other ways of cross-platform communication), this could be a major
problem.

Although we live today in Windows world and think mostly in Windows way, C++ was never developed with
Windows in mind. A huge amount of effort was done in the last 10-12 years to minimize the cross platform problems
in C++. Choosing 1 for TRUE makes all these possible problems go away.

And TRUE = 1 matches the usual convention in logical calculations (boolean algebra?)...

Anyway, as you know, in C/C++ any non-zero value is TRUE. This also means that you can never be absolutely
sure that TRUE has a specific int value. So, NEVER test a logical value against TRUE in C++. ALWAYS test it against
FALSE.

Vlad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform