
Originally Posted by
bluedes
what if choice is integer, and 0 is considered false..
I think boolean expressions evaluate 0 as false.
you can have like this:
if(getChoice()) or if(!getChoice()) or if(getChoice() > 0)
What language and compiler you are referring by the way?
other than that, I normally don't place function in any of my "if statement", where I need the funcion's returned value/reference, and the function itselfs is having another function calls or any small-medium operations, that makes some overhead.
eg.
if(MyFunc())
{
x = MyFunc();
}
the above code process functions twice.
Real world situation.
a function that returns two element, first is boolean, second is an object.
BAD CODE:
if(MyFunc()[0])
{
anObject = MyFunc()[1];
}
GOOD CODE:
anObject=MyFunc();
if(anObject[0])
{
//do whatever you want in anObject[1];
}

Originally Posted by
bluedes
if ((bool) choice)
and I seldom/haven't seen a code casting some variable to boolean type, integer can be treated as boolean values, however boolean type variables are two bits size only.