Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29285 Discussions

External procedures with the same name as intrinsic procedures

Arjen_Markus
Honored Contributor II
924 Views
Hello,

we had a rather awkward problem with a routine that we called IIDIM. This is the same name as one
of the specific routines/functions forthe DIMintrinsic function. It turned out that the intrinsic function was
called, not our function - completely according to the Fortran standard of course.

My question is: is there a compiler option in Intel Fortran that flags routine names identical to the names
of intrinsic procedures? I could not find any in the help information.

Another thing: does the set of intrinsic procedures depend on the use of modules like IFPORT? From the
documentation I do get that impression, but I would like to make sure.

Regards.

Arjen

0 Kudos
6 Replies
jimdempseyatthecove
Honored Contributor III
924 Views
Arjen,

Do you have (and use) and explicit interface to your routine? If not, try adding one.

Note, IDEM works as a generic function for integer(1), integer(2), integer(4) and integer(8) so
if your IIDEM takes two integer arguments .and. you are relying on the compiler for promotion/demotion then there may be some ambiguity which results in the incorrect (non-intended) function being called. In this situation you may need to make a generic interface to your IIDEM using permutations of acceptible argument types.

Jim Dempsey


0 Kudos
Arjen_Markus
Honored Contributor II
924 Views
Hi Jim,

this problem turned up more or less out of the blue, as our function has beenaround
for a long while (at least as far as I know). The followingcode gives two warnings with gfortran -Wall,
but ifort -warn:all does not complain:

! intrinsic.f90 --

! Define a function with the same name as an intrinsic

! Any messages?

!

real function sin( x )

real :: x

sin = x + 1.0

end function sin

real function dim( x, y )

real :: x, y

dim = x + y

end function dim

I actually do see the generated interfaces appear. Hm, I should check whether
my version is indeed used in this case.

Regards,

Arjen

0 Kudos
Arjen_Markus
Honored Contributor II
924 Views
If I add a small test program to this code:

program test_intrinsic
real :: x, y,z
x = 1.0
y= 2.0
z = sin(x)
write(*,*) 'Sin(x) =', z
z = dim(x,y)
write(*,*) 'Dim(x,y) =', z
end program test_intrinsic

I get the values as computed by the intrinsic functions, notbythe above ones:

Sin(x) = 0.8414710
Dim(x,y) = 0.0000000E+00

I do get the generated modules:

!COMPILER-GENERATED INTERFACE MODULE: Fri May 13 14:30:45 2011

MODULE SIN__genmod

INTERFACE

FUNCTION SIN(X) RESULT(SIN_0)

REAL(KIND=4) :: X

REAL(KIND=4) :: SIN_0

END FUNCTION SIN

END INTERFACE

END MODULE SIN__genmod


If I put the two functions in a module, and use that module, then:

Sin(x) = 2.000000
Dim(x,y) = 3.000000

so in that case my versions are indeed called.

Regards,

Arjen

0 Kudos
Steven_L_Intel1
Employee
924 Views
There is no option to warn if you have a procedure with the same name as an intrinsic, as that is perfectly standard Fortran. The language provides a way to guard against conflicts - either an explicit interface as described above, or the EXTERNAL statement.
0 Kudos
jimdempseyatthecove
Honored Contributor III
924 Views
Put your interface, not the compiler generated interface, in a module you supply, then USE that module name if the routines that you wish to use your IIDIM (and/or other conflicting names). Do not rely on auto-magicly generated interfaces for this purpose. You have seenthat anbiguous implicit/specified USE interfaces results in not getting what you want. IOW explicitly tell the compiler what you want.

Jim Dempsey
0 Kudos
Arjen_Markus
Honored Contributor II
924 Views

Steve, Jim,

I understand the issues - this occurred in a large program that is slowly being converted in Fortran 90.
I keep promoting modules as a means to avoid this and other nastiness, but it takes a lot of time to
get there.

Thanks for the replies.

Regards,

Arjen

0 Kudos
Reply