Does C/C++ offer any guarantee on minimal execution time?

后端 未结 4 458
心在旅途
心在旅途 2021-02-02 07:04

Why do compilers seems to be polite toward loops that do nothing and do not eliminate them?

Does the C standard require loops to take some time?

Example, the f

4条回答
  •  广开言路
    2021-02-02 07:30

    No, there is no guarantee: (quotation from N1570, 5.1.2.3 Program execution)

    1 The semantic descriptions in this International Standard describe the behavior of an abstract machine in which issues of optimization are irrelevant.

    Anyway, the C standard only specifies the behaviour of your program when it is executed on an abstract machine, which can have infinite memory and/or CPUs.

提交回复
热议问题