Advanced C++
Q99 / 100

What is the "as-if" rule in C++ optimization?

Correct! Well done.

Incorrect.

The correct answer is B) Compilers may transform code in any way as long as the observable behavior (I/O, volatile accesses, thread synchronization) is unchanged

B

Correct Answer

Compilers may transform code in any way as long as the observable behavior (I/O, volatile accesses, thread synchronization) is unchanged

Explanation

The as-if rule allows loop unrolling, function inlining, dead code elimination, and instruction reordering as long as the final observable behavior matches the abstract machine.

Progress
99/100