Does “undefined behaviour” extend to compile-time?

前端 未结 5 2001
梦毁少年i
梦毁少年i 2020-12-03 10:56

We\'ve all heard the warnings that if you invoke undefined behaviour in C or C++, anything at all can happen.

Is this limited to any ru

5条回答
  •  不知归路
    2020-12-03 11:46

    At least some forms of Undefined Behavior may cause the act of compilation itself to behave in ways outside the jurisdiction of the Standard. For example, the authors of the Standard did not want to preclude the use of something like

    #include `someProg arg`
    

    or

    #pragma exec-include "someProg arg"
    

    as a means of running someProg with the given arguments and treat the output of such program as though it would be part of the source text. Since the the behavior of a programs invoked by such syntax would be outside the jurisdiction of the Standard, such constructs are--from the point of view of the Standard--simply regarded as invoking UB at compile time.

提交回复
热议问题