Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
BOOL Datatype
Message
From
12/04/2000 08:50:48
 
 
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Title:
Miscellaneous
Thread ID:
00357504
Message ID:
00358606
Views:
15
>>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.

>I might be being pedantic here, but any non-zero value is NOT FALSE, only 1 non-zero value is TRUE (as defined with #define or enum or some otherway), as you state - never specifically check for TRUE.

From the view of C/C++ (which I really don't think George was getting at) another way of looking at is that

if ( A == FALSE )
and
if ( A == TRUE )

are both integer expressions, comparing specific integer values, where TRUE & FALSE have specific integer values and A can validly be neither TRUE or FALSE, so an expression like :

if ( A == FALSE )
printf( "False" ) ;
else if ( A == TRUE )
printf( "True" ) ;
else
printf( "Maybe" ) ;
can printout Maybe

if ( A )
and
if ( ! A )

are logical expressions, and A must be either TRUE or FALSE. The similar looking but not identical expession :

if ( ! A )
printf( "False" ) ;
else if ( A )
printf( "True" ) ;
else
printf( "Maybe" ) ;

can never printout Maybe

(Guess George is getting sorry now he made his interesting observation)
Mike

"I can live with doubt and uncertainty and not knowing. I think it is much more interesting to live not knowing than to have answers that might be wrong." - Richard Feynman
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform