Is the behaviour of the compiler undefined, with Undefined Behaviour?

后端 未结 7 765
旧时难觅i
旧时难觅i 2021-01-03 08:48

When I answered this question, I wrote:

First, it is important to note that it is not only the behaviour of the user program that is undefined, it is

7条回答
  •  别那么骄傲
    2021-01-03 09:04

    is it only the behaviour of the translated machine code that is undefined, or is the behaviour of the compiler undefined, too?

    The ISO C and C++ describe what a C and C++ program look like. They do not describe the environment they run in. We generally use the term compiler to refer to the tool that translates C and C++ into machine code; formally, however, the term used is implementation which is definitely wider.

    Therefore, the only behavior which is undefined is the one of the program. This is also given by the definition of UB:

    undefined behavior
    behavior, upon use of a nonportable or erroneous program construct or of erroneous data, for which this International Standard imposes no requirements

提交回复
热议问题