如何检测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 –