Khác nhé:
- Undefined behavior là hành vi không thể nghĩ bàn với số khả năng vô hạn
- Unspecified behavior là hành vi không thể nghĩ bàn trong những khả năng được quy định sẵn
- Implementation-defined behavior là phải nhất quán trong một compiler.
Trích dẫn
N4296, 1.9.2
Certain aspects and operations of the abstract machine are described in this International Standard as
implementation-defined (for example, sizeof(int)). These constitute the parameters of the abstract machine. Each implementation shall include documentation describing its characteristics and behavior in these respects.
N4296, 1.9.3
Certain other aspects and operations of the abstract machine are described in this International Standard as unspecified […]. Where possible, this International Standard defines a set of allowable behaviors. These define the nondeterministic aspects of the abstract machine. An instance of the abstract machine can thus have more than one possible execution for a given program and a given input.
N4296, 1.9.4
Certain other operations are described in this International Standard as undefined (for example, the effect of attempting to modify a const object)
N4296, 1.9.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)
Ví dụ: Xét biểu thức ++i + i++
N4296, 1.9.13
Given any two evaluations A and B, if A is sequenced before B, then the execution of A shall precede the execution of B. If A is not sequenced before B and B is not sequenced before A, then A and B are unsequenced.
N4296, 1.9.15
Except where noted, evaluations of operands of individual operators and of subexpressions of individual expressions are unsequenced. […] If a side effect on a scalar object is unsequenced relative to either another side effect on the same scalar object or a value computation using the value of the same scalar object, and they are not potentially concurrent (1.10), the behavior is undefined.