Consider the following code:
program test
real :: out
out = f(1)
write(*,*) out
write(*,*) f(1)
contains
function f(i)
integer, intent(in) :: i
!> Result
real :: f
write(*,*) 'in f', i
f = i*2.0
end function f
end program test
The write statement inside the f
function is supposed to be for debugging purposes only. The first call to f
executes correctly, whereas the second call through the write
statement results in the program hanging up. The output is:
in f 1
2.0000000000000000
Does anyone know what is happening here?
I tested the code on macOS (M1 Max Macbook) using gfortran compiler:
gfortran-mp-11 -fimplicit-none -fdefault-real-8 test.f90 -o test.exe; ./test.exe
Same results using either gcc11 (MacPorts gcc11 11.2.0_1) or gcc-devel (MacPorts gcc-devel 12-20220101_2+enable_stdlib_flag).