# Gfortran "ffpe-trap" compiling options

**URL:** https://fortran-lang.discourse.group/t/gfortran-ffpe-trap-compiling-options/1969
**Category:** Help
**Created:** [October 1, 2021, 2:47am UTC](https://fortran-lang.discourse.group/t/gfortran-ffpe-trap-compiling-options/1969 "2021-10-01T02:47:48Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Euler-37](https://avatars.discourse-cdn.com/v4/letter/e/b19c9b/32.png) [@Euler-37](https://fortran-lang.discourse.group/u/Euler-37)
#### Post date: [October 1, 2021, 2:47am UTC](https://fortran-lang.discourse.group/t/gfortran-ffpe-trap-compiling-options/1969/1 "2021-10-01T02:47:48Z")

</div>

I want to use gfortran compiling options `-g -fbacktrace -ffpe-trap=zero,overflow,underflow,invalid,denormal -Wall -fcheck=all` to compile the test code which has invalid IEEE\_XXXX\_FLAG.

compiler: WSL ubuntu 20.04 gfortran 9.3

The code like this

```auto
program main
    implicit none
    real::a,b,c
    a=0.0
    b=0.0
    c=a/b
    write(*,*)c
    pause
end program main

```

If I don’t use these options, the output shows below (`pause` is important)

```auto
$ gfortran test.f90 && ./a.out
test.f90:8:9:

    8 | pause
      | 1
Warning: Deleted feature: PAUSE statement at (1)
              NaN
PAUSE
To resume execution, type go. Other input will terminate the job.

Note: The following floating-point exceptions are signalling: IEEE_INVALID_FLAG

```

If I use these options

```auto
$ gfortran -g -fbacktrace -ffpe-trap=zero,overflow,underflow,invalid,denormal -Wall -fcheck=all test.f90 && ./a.out
test.f90:8:9:

    8 | pause
      | 1
Warning: Deleted feature: PAUSE statement at (1)

```

just show this.

However ,When I use these compiling options on [godbolt](https://godbolt.org/),  
Its output

 ![gnuoptions](https://global.discourse-cdn.com/free1/uploads/fortran_lang/original/1X/7bba04055b3ce2214b9172ff14d5e05d6944cdf3.png)

The more important information **.f90:6** shows.

So Can personal computer show the same error info?

Thanks

---

<div class="post-metadata">

### Author: ![Beliavsky](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@Beliavsky](https://fortran-lang.discourse.group/u/Beliavsky)
#### Post date: [October 1, 2021, 3:32am UTC](https://fortran-lang.discourse.group/t/gfortran-ffpe-trap-compiling-options/1969/2 "2021-10-01T03:32:58Z")

</div>

To silence the warning about `pause`, you can use the `-std=legacy` option. On Windows 10, using `GNU Fortran (GCC) 12.0.0 20210718` from [equation.com](http://equation.com) and compiling your code with

`gfortran -std=legacy -g -fbacktrace -ffpe-trap=zero,overflow,underflow,invalid,denormal -Wall fcheck=all trap.f90`

gives when running

```auto
Program received signal SIGFPE: Floating-point exception - erroneous arithmetic operation.

Backtrace for this error:
#0 0x42f94b
#1 0x425814
#2 0x40ca31
#3 0xfb2ad57
#4 0x106c826e
#5 0x106559c9
#6 0x106c727d
#7 0x40159f
#8 0x401668
#9 0x4013c0
#10 0x4014f5
#11 0xe7254df
#12 0x1062485a
#13 0xffffffff

```

On WSL 2, using `GNU Fortran (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0` with the same options as above gives at run time

```auto
Program received signal SIGFPE: Floating-point exception - erroneous arithmetic operation.

Backtrace for this error:
#0 0x7f60ece9b700 in ???
#1 0x7f60ece9a8a5 in ???
#2 0x7f60eccce20f in ???
#3 0x555c224d41fa in MAIN__
	at /mnt/c/fortran/test/trap.f90:6
#4 0x555c224d42c3 in main
	at /mnt/c/fortran/test/trap.f90:9
Floating point exception

```

I wonder why we are getting different results for WSL. Are you using WSL 1 or 2? You can check by running `wsl -l -v` from Windows CMD.

---

<div class="post-metadata">

### Author: ![Euler-37](https://avatars.discourse-cdn.com/v4/letter/e/b19c9b/32.png) [@Euler-37](https://fortran-lang.discourse.group/u/Euler-37)
#### Post date: [October 1, 2021, 3:39am UTC](https://fortran-lang.discourse.group/t/gfortran-ffpe-trap-compiling-options/1969/3 "2021-10-01T03:39:29Z")

</div>

I am using WSL 1 ,So may it is the key 🤔,Thanks a lot 😀

---

<div class="post-metadata">

### Author: ![Euler-37](https://avatars.discourse-cdn.com/v4/letter/e/b19c9b/32.png) [@Euler-37](https://fortran-lang.discourse.group/u/Euler-37)
#### Post date: [March 4, 2022, 9:55am UTC](https://fortran-lang.discourse.group/t/gfortran-ffpe-trap-compiling-options/1969/4 "2022-03-04T09:55:32Z")

</div>

update : using `gcc version 11.2.0 (GCC)` from [equation.com](http://equation.com/) gives this error

> [@Beliavsky](#):
>
> ```auto
> Program received signal SIGFPE: Floating-point exception - erroneous arithmetic operation.
> 
> Backtrace for this error:
> #0 0x42f94b
> #1 0x425814
> #2 0x40ca31
> #3 0xfb2ad57
> #4 0x106c826e
> #5 0x106559c9
> #6 0x106c727d
> #7 0x40159f
> #8 0x401668
> #9 0x4013c0
> #10 0x4014f5
> #11 0xe7254df
> #12 0x1062485a
> #13 0xffffffff
> 
> ```

and if using gdb debug the binary`gdb a.exe`,it shows

```auto
> r
.......
Thread 1 received signal SIGFPE, Arithmetic exception.
0x00007ff7812e15a0 in MAIN__ () at 1.f90:6
6 c=a/b

```

and gives `line 6`. By the way ,WSL1 shows nothing as before.
