Consider the code:
subroutine func(i) bind(c)
use, intrinsic :: ISO_C_BINDING, only: c_float
implicit none
real(c_float), value :: i
print *, i, "+", i, "=", i + i
end subroutine
program main
use, intrinsic :: ISO_C_BINDING, only: c_float
implicit none
real(c_float) :: i = 1.0
call func(i)
end program
It displays 5.61379690E-30 + 5.61379690E-30 = 1.12275938E-29
, which is of course wrong. Only if I add an explicit interface, it outputs the correct results:
subroutine func(i) bind(c)
use, intrinsic :: ISO_C_BINDING, only: c_float
implicit none
real(c_float), value :: i
print *, i, "+", i, "=", i + i
end subroutine
program main
implicit none
interface
subroutine func(i)
real, value :: i
end subroutine func
end interface
real :: i = 1.0
call func(i)
end program
I then get 1.00000000 + 1.00000000 = 2.00000000
which is correct.
But what is causing the error here? Why is an extra interface required that doesn't add any new information?
I use gfortran, GCC, Version 7.4.0