如何檢測D中的整數溢出? (檢查進位標誌?)檢測整數溢出
原來的例子:
ubyte a = 100;
ubyte b = 200;
ubyte c = a + b;
// c can't represent 300; how to detect the overflow now?
修訂例如:
uint a = 2_000_000_000;
uint b = 3_000_000_000;
uint c = a + b;
// c can't represent 5_000_000_000; how to detect the overflow now?
用乘法和前/後遞增
也。
看看相同的問題爲C + + http://stackoverflow.com/questions/199333/best-way-to-detect-integer-overflow-in-cc –
和大會http://stackoverflow.com/問題/ 3925528/x86-assembly-inc-and-dec-instruction-and-overflow-flag –