Is it legal for a C++ optimizer to reorder calls to clock()?

前端 未结 7 1900
清歌不尽
清歌不尽 2020-12-02 10:55

The C++ Programming Language 4th edition, page 225 reads: A compiler may reorder code to improve performance as long as the result is identical to that of the s

7条回答
  •  执念已碎
    2020-12-02 11:30

    Let's suppose that the sequence is in a loop, and the veryLongComputation () randomly throws an exception. Then how many t0s and t1s will be calculated? Does it pre-calculate the random variables and reorder based on the precalculation - sometimes reordering and sometimes not?

    Is the compiler smart enough to know that just a memory read is a read from shared memory. The read is a measure of how far the control rods have moved in a nuclear reactor. The clock calls are used to control the speed at which they are moved.

    Or maybe the timing is controlling the grinding of a Hubble telescope mirror. LOL

    Moving clock calls around seems too dangerous to leave to the decisions of compiler writers. So if it is legal, perhaps the standard is flawed.

    IMO.

提交回复
热议问题