http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50975
Bug #: 50975 Summary: Logical operators evaluated in wrong order if no side effects Classification: Unclassified Product: gcc Version: 4.6.2 Status: UNCONFIRMED Severity: major Priority: P3 Component: c AssignedTo: unassig...@gcc.gnu.org ReportedBy: gcc.h...@gmail.com gcc 4.6.2 -Os If the expressions either side of a logical operator (|| or &&) have no side effects, gcc sometimes evaluates them in the wrong order. See the example below. Of course the code works, but the standard is clear, logical operators GUARANTEE left to right evaluation. In this case people use the feature as a micro optimization, putting the most likely to succeed case first with || or vice-versa with &&. ----------------------------------- #include <stdio.h> int main( int argc, char *argv[] ) { char *last = argv[1]; if( *last == 10 || *last == 13 ) --last; printf("last = %p\n", last ); return 0; } --------------------------------------------- movb (%eax), %dl # *last_3, D.2517 cmpb $13, %dl #, D.2517 je .L4 #, cmpb $10, %dl #, D.2517 jne .L2 #, .L4: decl %eax # last .L2: --------------------------------------------