- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Replace this:
Here's my rule: If you are declaring the same thing twice, you're doing it wrong.
[plain]interface ciswith this:
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]
[plain]interface cisWhat you had done was declare that the specific functions were external, and then declared them again as contained procedures.
module procedure cis4
module procedure cis8
end interface[/plain]
Here's my rule: If you are declaring the same thing twice, you're doing it wrong.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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].
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve,
This works. Thanks,
Sepp
This works. Thanks,
Sepp

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page