[討論] U.B. due to unsequenced access

看板b04902xxx作者 (johnchen902)時間8年前 (2015/10/24 13:58), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
根據 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); ------------------------------------ int f(int *x) { return *x = 3; } f(&i) + i; 以上希望大家能理解 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.112.16.137 ※ 文章網址: https://www.ptt.cc/bbs/b04902xxx/M.1445666306.A.A66.html
文章代碼(AID): #1MAnu2fc (b04902xxx)