[討論] 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