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.

Overloading user-defined procedures

seppun
Beginner
959 Views
The enclosed program defines a generic function with two realizations, one for real/complex*4 and the other one for real/complex*8. When I try to compile it, I get the error message "the name of the internal procedure conflicts with a name in the encompassing scoping unit. [CIS4]" and the same for [CIS8]. What am I doing wrong? We have the version 10.0.011 Fortran compiler.

program test
!defines a generic function cis(x) = cos(x) + i * sin(x)
!with specific names cis4 (for real*4) and cis8 (for real*8)
implicit none
interface cis
function cis4(x)
real(4), intent(in) :: x
complex(4) :: cis4
end function cis4

function cis8(x)
real(8), intent(in) :: x
complex(8) :: cis8
end function cis8
end interface

real(4) :: r4 = 1
complex(4) :: c4
real(8) :: r8 = 1
complex(8) :: c8

c4 = cis(r4)
c8 = cis(r8)

contains

function cis4(x)
real(4), intent(in) :: x
complex(4) :: cis4
cis4 = cmplx(cos(x), sin(x))
end function cis4

function cis8(x)
real(8), intent(in) :: x
complex(8) :: cis8
cis8 = cmplx(cos(x), sin(x))
end function cis8

end program test
0 Kudos
4 Replies
Steven_L_Intel1
Employee
959 Views
Replace this:
[plain]interface cis
function cis4(x)
real(4), intent(in) :: x
complex(4) :: cis4
end function cis4

function cis8(x)
real(8), intent(in) :: x
complex(8) :: cis8
end function cis8
end interface[/plain]
with this:
[plain]interface cis
module procedure cis4
module procedure cis8
end interface[/plain]
What you had done was declare that the specific functions were external, and then declared them again as contained procedures.

Here's my rule: If you are declaring the same thing twice, you're doing it wrong.
0 Kudos
seppun
Beginner
959 Views
Steve: I did what you suggested, and now I get the message "Error: the name of the internal procedure conflicts with a procedure name in the MODULE PROCEDURE statement [CIS4]", and the same for [CIS8].

0 Kudos
Steven_L_Intel1
Employee
959 Views
Sorry about that. What I missed was that you were doing this in a PROGRAM rather than a MODULE. If you want to use CONTAINed procedures, the whole thing has to be in a module, like this:

[plain]module cis_mod
!defines a generic function cis(x) = cos(x) + i * sin(x)
!with specific names cis4 (for real*4) and cis8 (for real*8)
implicit none
interface cis
module procedure cis4
module procedure cis8
end interface
contains

function cis4(x)
real(4), intent(in) :: x
complex(4) :: cis4
cis4 = cmplx(cos(x), sin(x))
end function cis4

function cis8(x)
real(8), intent(in) :: x
complex(8) :: cis8
cis8 = cmplx(cos(x), sin(x))
end function cis8

end module cis_mod

program test
use cis_mod


real(4) :: r4 = 1
complex(4) :: c4
real(8) :: r8 = 1
complex(8) :: c8

c4 = cis(r4)
c8 = cis(r8)

end program test

[/plain]

0 Kudos
seppun
Beginner
959 Views
Steve,

This works. Thanks,

Sepp
0 Kudos
Reply