[問題] 關於Undefined Behavior的一些疑問[已解決]
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
gcc
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
無
問題(Question):
1.
最近在看http://blog.regehr.org/archives/213
裡面有討論一些Undefined Behavior,但是有些不是很懂,
因此來詢問大家,
為什麼a變數要檢查INT32_MIN呢?
b為-1會有什麼問題?
2.
還有所謂的side effect是指a=b++ + ++b的問題嘛?
因為我好像一值以來,把它和bound問題混在一起想,
作者用asm當例子,我就更難理解了!
程式碼(Code):(請善用置底文網頁, 記得排版)
int32_t safe_div_int32_t (int32_t a, int32_t b)
{
if ((b == 0) || ((a == INT32_MIN) && (b == -1)))
{
report_integer_math_error();
return 0;
}
else
{
return a / b;
}
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.220.204.217
→
07/06 10:10, , 1F
07/06 10:10, 1F
→
07/06 10:10, , 2F
07/06 10:10, 2F
※ 編輯: angleevil 來自: 61.220.204.217 (07/06 10:18)
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章