C++ What is the earliest undefined behavior can manifest itself?

前端 未结 5 1348
臣服心动
臣服心动 2021-01-17 19:48

I\'m aware that undefined behavior can potentially cause anything, which makes any program containing UB potentially meaningless. I was wondering if there is any way to iden

5条回答
  •  离开以前
    2021-01-17 20:07

    which makes any program containing UB potentially meaningless

    Not quite right. A program can't "contain" UB; when we say "UB" that is short for: the program's behaviour is undefined. All of it!

    So the program is not just potentially, but actually, meaningless, from the start.

    [intro.execution]/5: A conforming implementation executing a well-formed program shall produce the same observable behavior as one of the possible executions of the corresponding instance of the abstract machine with the same program and the same input. However, if any such execution contains an undefined operation, this International Standard places no requirement on the implementation executing that program with that input (not even with regard to operations preceding the first undefined operation).

提交回复
热议问题