当我忘记指定接口函数的返回类型时,为什么 GCC 不警告我?对我来说,这种行为接缝出乎意料。你对此有什么看法?
这是测试程序(取消注释第 6 行,它可以正常工作):
program returntest
implicit none
interface
function givehalf(Y)
double precision :: Y
!double precision :: givehalf !<-- Uncomment this line
end function givehalf
end interface
double precision :: temp
temp=givehalf(5.151515d0)
print*, 'result= ',temp
end program returntest
function givehalf(Y)
implicit none
double precision :: Y
double precision :: givehalf
print*, 'Y= ',Y
givehalf=Y/2.0d0
print*, 'return Y/2',givehalf
return
end function givehalf
结果是这样的:
user@bapf028dl:/media/disk> gfortran44 -Wall return-test.f90
user@bapf028dl:/media/disk> ./a.out
Y= 5.1515149999999998
return Y/2 2.5757574999999999
result= -1.0579199790954590
user@bapf028dl:/media/disk> ifort return-test.f90
user@bapf028dl:/media/disk> ./a.out
Y= 5.15151500000000
return Y/2 2.57575750000000
result= 2.57575750350952