Dividing by zero in a constant expression
问题 My toy compiler crashes if I divide by zero in a constant expression: int x = 1 / 0; Is this behaviour allowed by the C and/or C++ standards? 回答1: The mere presence of 1 / 0 does not permit the compiler to crash. At most, it is permitted to assume that the expression will never be evaluated, and thus, that execution will never reach the given line. If the expression is guaranteed to be evaluated, the standard imposes no requirements on the program or compiler. Then the compiler can crash. 1 /