Hello,
Somehow I was unable to find about which operators in C/C++ can be used with confidence about their sequential evaluation order. If you know for sure, please post!
For example with && operator:
1 2 3 4 5 6 7 8 9 10 11 12 13
if ( target_->table_ &&
target_->table_[0] &&
!target_->table_[0][0].key )
{
advance_indexes();
}
if ( target_->table_ )
if ( target_->table_[0] )
if ( !target_->table_[0][0].key )
{
advance_indexes();
}
Will those two perform equally always and with whatever C/C++ compiler?
in any statement which has a couple of &&'s, if any of the condition evaluates to false rest of the conditions are not considered. this is because the compiler is sure that one false will make the whole statement false.
similary for a ||, if any of the condition evaluates to true rest of the conditions are ignored because again the compiler is sure that the whole condition is true.
so what you have written is true, both the conditions are same.
to have a proof do this:
1 2 3 4 5 6 7 8
int i = 1;
if(i < 0 && i++ < 10)
{
cout << "testing" << endl;
}
cout << i << endl;
Thanks, but I have tried already. I was reading, that arguments of functions are evaluated randomly and was not sure about operators. So, list of sequential ones is what I am missing... Only "&&" and "||"?