Can the C compiler optimizer violate short-circuiting and reorder memory accesses for operands in a logical-AND expression?

后端 未结 4 1743
傲寒
傲寒 2021-01-18 04:50

We know that logical-AND operator (&&) guarantees left-to-right evaluation.

But I am wondering if the compiler optimizer can ever reorder the me

4条回答
  •  终归单人心
    2021-01-18 05:17

    The system can evaluate b->foo until such time as it hits something that exceeds its ability to execute speculatively. Most modern systems can handle a speculative fault and ignore the fault if it turns out that the results of the operation are never used.

    So it's purely up to the capabilities of the compiler, CPU, and other system components. So long as it can ensure there are no visible consequences to conforming code, it can execute (almost) anything it wants (almost) any time it wants.

提交回复
热议问题