[讨论] U.B. due to unsequenced access

楼主: johnchen902 (johnchen902)   2015-10-24 13:58:24
根据 C11 标准 §6.5
2 If a side effect on scalar object is unsequenced relative to either
a different side effect on a same scalar object or a value computation
using the value of the same scalar object, the behavior is undefined.
以下数个例子都是未定义的行为
(i = 3) + i;
(i++) + (++i);
(i = 3) + (i = 5);
(i = -1) + (i = -1);
i ^= j ^= i ^= j;
以下是有定义的行为:
i = 3;
i = 5;
(i = 3), (i = 5);
(i = 3) && (i = 5);
(i = 0) || (i = 8);
(i = 1) ? (i = 3) : (i = 5);

Links booklink

Contact Us: admin [ a t ] ucptt.com