Why doesn't 'd /= d' throw a division by zero exception when d == 0?

后端 未结 4 1209
深忆病人
深忆病人 2021-02-02 04:50

I don\'t quite understand why I don\'t get a division by zero exception:

int d = 0;
d /= d;

I expected

4条回答
  •  甜味超标
    2021-02-02 05:20

    Note that you can have your code generate a C++ exception in this (and other cases) by using boost safe numerics. https://github.com/boostorg/safe_numerics

提交回复
热议问题