运行代码后,这是在cygwin下,gdb转储了trace。
$ cat sigfpe.exe.stackdump
Exception: STATUS_INTEGER_DIVIDE_BY_ZERO at rip=00100401115
rax=0000000000000000 rbx=000000000022CB20 rcx=0000000000000001
rdx=0000000000000000 rsi=000000060003A2F0 rdi=0000000000000000
r8 =0000000000000000 r9 =0000000000000000 r10=0000000000230000
r11=0000000000000002 r12=0000000000000000 r13=0000000000000001
r14=000000000022CB63 r15=000000000022CB64
rbp=000000000022CAD0 rsp=000000000022CAA0
program=C:\cygwin64\home\luser\sigfpe.exe, pid 6808, thread main
cs=0033 ds=002B es=002B fs=0053 gs=002B ss=002B
Stack trace:
Frame Function Args
0000022CAD0 00100401115 (00000000020, 30001000000FF00, 0018004830F, 0000022D680 )
0000022CBC0 00180048380 (00000000000, 00000000000, 00000000000, 00000000000)
00000000000 0018004607C (00000000000, 0003E704021, 00000000000, 0000000002D)
00000000000 00180046114 (00000000000, 00000000000, 00000000000, 00000000000)
00000000000 00100401191 (00000000000, 00000000000, 00000000000, 00000000000)
00000000000 00100401010 (00000000000, 00000000000, 00000000000, 00000000000)
00000000000 000772E59CD (00000000000, 00000000000, 00000000000, 00000000000)
00000000000 0007741B981 (00000000000, 00000000000, 00000000000, 00000000000)
End of stack trace
线索在行动中i += (i % i)
当循环初始值为0时,当然除以零错误。
你试过捕捉信号吗?
查看第 265 页的C11 标准, SIGFPE -错误的算术运算,例如零除或导致溢出的操作
这不是编译器错误,而是实现定义的。