This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
External function passed to Interface function
- From: Jon Hurst <jhurst at ucar dot edu>
- To: fortran at gcc dot gnu dot org
- Date: Tue, 24 Feb 2009 12:02:22 -0700
- Subject: External function passed to Interface function
Hello,
The attached piece of code is giving me the following errors with
gfortran 4.3.3 and some earlier versions (4.1.2).
gfortran -o test2 test2.f90
test2.f90:46.28:
res = recSum( a, res, UserFunction, UserOp )
1
Error: Type/rank mismatch in argument 'userfunction' at (1)
test2.f90:25.20:
rs = recSum( a, b, test1, sumInts )
1
Error: Type/rank mismatch in argument 'userfunction' at (1)
The code compiles and runs on pgf90 7.0-7 and gfortran 4.0.3.
Removing the opfunc argument from the test1 function seems to fix the
error, but removes the desired functionality. I'm curious as to whether
this code breaks some rules from the specification, or whether this is a
gfortran issue. I should emphasize that the earlier version of gfortran
(4.0.3) handled this code successfully.
Thanks for the assistance,
Jonathan Hurst
Software Engineer
National Center for Atmospheric Research
MODULE funcs
CONTAINS
INTEGER FUNCTION test1(a,b,opfunc)
INTEGER :: a,b
INTEGER, EXTERNAL :: opfunc
test1 = opfunc( a, b )
END FUNCTION test1
INTEGER FUNCTION sumInts(a,b)
INTEGER :: a,b
sumInts = a + b
END FUNCTION sumInts
END MODULE funcs
PROGRAM test
USE funcs
INTEGER :: rs
INTEGER, PARAMETER :: a = 2, b = 1
rs = recSum( a, b, test1, sumInts )
write(*,*) "Results", rs
CONTAINS
RECURSIVE INTEGER FUNCTION recSum( a,b,UserFunction,UserOp ) RESULT( res )
IMPLICIT NONE
INTEGER :: a,b
INTERFACE
INTEGER FUNCTION UserFunction(a,b,opfunc)
INTEGER :: a,b
INTEGER, EXTERNAL :: opfunc
END FUNCTION UserFunction
END INTERFACE
INTEGER, EXTERNAL :: UserOp
res = UserFunction( a,b, UserOp )
if( res .lt. 10 ) then
res = recSum( a, res, UserFunction, UserOp )
end if
END FUNCTION recSum
END PROGRAM test