Ron Lima wrote:
>> if(i==1 && func1() ) do something <snip> can i rely that in any
>> system func1 will never run if i!=1 (so first agument is checked
>> first)
>
> If you need func1 to run, dispite the value of 1, then this
> expression will not work for you, since if i is different from 1, the
> expression containing fun1 will not be evaluated.
I've included the bit you snipped, where he says he *does not* want it
to run if i != 1.
> It is considered poor style relying on the evaluation order of
> expressions since it may cause confusion on the reader of your code.
I think the use of "short-circuit" logical operators is pretty idiomatic
for programmers of many languages.
> It is a better idea to rewrite your code in a way to get the function
> calls outside expressions in order to make it clearer.
Having function calls outside of expressions is not always possible and
not necessarily clearer.
consider:
int myFunc getVal() {
return 42;
}
int main() {
int myInt = getVal();
}
How do you suggest I remove that function call from the expression?
Actually, in the case of initialisation, that's easy:
int myInt(getVal());
But not for assignment.
Ben Pope
--
I'm not just a number. To many, I'm known as a string...
|