When I call the following function, it returns 1
as expected:
integer function my_func() result(myresult)
myresult = 1
end function my_func
But when I modify the name of the return value to start with the letter "r" then the function returns 0
.
integer function my_func() result(rresult)
rresult = 1
end function my_func
What is causing this? My first thought was that it related to implicit typing, but the function is within a module that specifies implicit none
.
Here is the complete module
module my_mod
implicit none
contains
integer function my_func() result(myresult)
myresult = 1
end function my_func
end module my_mod
I am using Fortran 90 and compiling with gfortran.
EDIT
Here is a complete program to demonstrate the problem
Makefile:
.PHONY: pytest clean
CYTHON_LIB = fortran_mods.cpython-37m-x86_64-linux-gnu.so
FFLAGS += -fdefault-real-8
pytest: $(CYTHON_LIB)
./tests.py
$(CYTHON_LIB): my_mod.F90
f2py -c -m fortran_mods my_mod.F90 --f90flags="$(FFLAGS)"
clean:
rm *.so
my_mod.F90:
module my_mod
implicit none
contains
!********************************************************
integer function my_func_without_r() result(myresult)
myresult = 1
end function
integer function my_func_with_r() result(rresult)
rresult = 1
end function
end module my_mod
tests.py
#!/usr/bin/env python3
import fortran_mods
from fortran_mods import *
print("with r:", my_mod.my_func_with_r())
print("without r:", my_mod.my_func_without_r())
The output when make pytest
is run and FFLAGS += -fdefault-real-8
is included in the Makefile is
with r: 0.0
without r: 1
and otherwise is
with r: 1.0
without r: 1