[英]Why Floating Point Exception (FPE) is not raised?
我试图在 Fortran 代码中捕获一些 FPE,但它似乎并不适用于所有环境。
我写了下面的代码作为例子:
program test
implicit none
doubleprecision, dimension(1) :: x ! used to lure the compiler
x(1) = 1d0
print *, 'start'
print *, 1d0 / (1d0 - x(1))
print *, 'end'
end program test
我的一台机器 (1) 使用 CentOS 7.6.1810、gfortran 4.8.5,并有一个 Intel Xenon 作为 CPU。 另一个 (2) 使用 Debian 10 Buster(实际上这个是在 Windows 10 上,但我使用 WSL 的 debian 应用程序),gfortran 9.2.0 并且有一个 Intel Core i5 作为 CPU。
当我使用编译上面的代码时
gfortran -o test -ffpe-trap=zero -fbacktrace -g -Og test.f90
在机器 1 上执行代码,我得到了我所期望的,即
$ ./test
start
Program received signal SIGFPE: Floating-point exception - erroneous arithmetic operation.
Backtrace for this error:
#0 0x7F2374BEC697
#1 0x7F2374BECCDE
#2 0x7F23740E827F
#3 0x400858 in MAIN__ at test.f90:9
然而,当我在机器 2 上做同样的事情时,我只得到:
$ ./test
start
为什么? 我应该怎么做才能在机器 2 上获得 SIGFPE(和其他信号)错误消息?
安装WSL 2解决了这个问题。
$ ./test
start
Program received signal SIGFPE: Floating-point exception - erroneous arithmetic operation.
Backtrace for this error:
#0 0x7feab2aee8b0 in ???
#1 0x7feab2aedae3 in ???
#2 0x7feab276883f in ???
at /build/glibc-vjB4T1/glibc-2.28/signal/../sysdeps/unix/sysv/linux/x86_64/sigaction.c:0
#3 0x4011fb in test
at /home/user/test/test.f90:9
#4 0x401299 in main
at /home/user/test/test.f90:11
Floating point exception
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.