>>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