| The implementation can assume that the program does not perpetrate undefined behavior (other than undefined behavior which the implementation itself defines as a documented extension). The only way the program can avoid perpetrating undefined behavior in the statement "x = x / 0" is if it does not execute that statement. Thus, to assume that the program does not invoke undefined behavior is tantamount to assuming that the program does not execute "x = x / 0". But "x = x / 0" follows printf("hello\n") unconditionally. If the printf is executed, then x = x / 0 will be executed. Therefore if the program does not invoke undefined behavior, it does not execute printf("hello\n") either. If the program can be assumed not to execute printf("hello\n"), there is no need to generate code for it. Look at the documentation for GCC's __builtin_unreachable: > Built-in Function: void __builtin_unreachable (void) > If control flow reaches the point of the __builtin_unreachable, the program is undefined. It is useful in situations where the compiler cannot deduce the unreachability of the code. The unreachable code assertion works by invoking undefined behavior! |
edit: this is in addition to the guarantees with regard to side effects that uecker says the C standard provides.