|
From: Aggro on 7 Apr 2008 16:24 I would like to know the answer to this for both C and C++ as I use both languages (usually in differen projects). Assume the code if( A && B ) Normally A is executed before B and this is how I have always believed it is guaranteed to work. But recently I got second hand information that the execution order is not quaranteed. E.g. B could be executed before A by some compilers. Different execution order could cause e.g. application to crash if we first test is the pointer valid and then call a function for that pointer: if( p && p->func() ) So. Is the execution order guaranteed by the standard in both C and C++ to be first A and then B or can it change e.g. because of optimization? Should I start writing my code in this format to be safe? if( p ) if( p->func() ) ...
|
Pages: 1 Prev: Arithmetic with char and long Next: && Operator precedence |