- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When I try to compile the following example, which constructs a generic procedure using another generic procedure, the compiler aborts with an internal error. I have tried the same example with the compilers of Compaq on Alpha and Windows and in both cases they give an error message, although its content is not very useful.
!----------------------------------------------------------------!
module Example
implicit none
interface Generic_Sub23
module procedure Sub2
module procedure Sub3
end interface Generic_Sub23
interface Generic_Sub
module procedure Sub1
module procedure Generic_Sub23
end interface Generic_Sub
contains
!------------------------------------!
subroutine Sub1(z)
complex, intent(in) :: z
end subroutine Sub1
!------------------------------------!
subroutine Sub2(x)
real, intent(in) :: x
end subroutine Sub3
!------------------------------------!
end module Example
!----------------------------------------------------------------!
program prueba
use Example
implicit none
integer :: x
real :: y
complex :: z
call Generic_Sub(x)
call Generic_Sub(y)
call Generic_Sub(z)
end program prueba
!----------------------------------------------------------------!
!----------------------------------------------------------------!
module Example
implicit none
interface Generic_Sub23
module procedure Sub2
module procedure Sub3
end interface Generic_Sub23
interface Generic_Sub
module procedure Sub1
module procedure Generic_Sub23
end interface Generic_Sub
contains
!------------------------------------!
subroutine Sub1(z)
complex, intent(in) :: z
end subroutine Sub1
!------------------------------------!
subroutine Sub2(x)
real, intent(in) :: x
end subroutine Sub3
!------------------------------------!
end module Example
!----------------------------------------------------------------!
program prueba
use Example
implicit none
integer :: x
real :: y
complex :: z
call Generic_Sub(x)
call Generic_Sub(y)
call Generic_Sub(z)
end program prueba
!----------------------------------------------------------------!
Link Copied
9 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ups, skipped some lines while copying the example file. Here is the correct/complete version:
!----------------------------------------------------------------!
module Example
implicit none
interface Generic_Sub23
module procedure Sub2
module procedure Sub3
end interface Generic_Sub23
interface Generic_Sub
module procedure Sub1
module procedure Generic_Sub23
end interface Generic_Sub
contains
!------------------------------------!
subroutine Sub1(z)
complex, intent(in) :: z
end subroutine Sub1
!------------------------------------!
subroutine Sub2(x)
real, intent(in) :: x
end subroutine Sub2
!------------------------------------!
subroutine Sub3(y)
integer, intent(in) :: y
end subroutine Sub3
!------------------------------------!
end module Example
!----------------------------------------------------------------!
program prueba
use Example
implicit none
integer :: x
real :: y
complex :: z
call Generic_Sub(x)
call Generic_Sub(y)
call Generic_Sub(z)
end program prueba
!----------------------------------------------------------------!
!----------------------------------------------------------------!
module Example
implicit none
interface Generic_Sub23
module procedure Sub2
module procedure Sub3
end interface Generic_Sub23
interface Generic_Sub
module procedure Sub1
module procedure Generic_Sub23
end interface Generic_Sub
contains
!------------------------------------!
subroutine Sub1(z)
complex, intent(in) :: z
end subroutine Sub1
!------------------------------------!
subroutine Sub2(x)
real, intent(in) :: x
end subroutine Sub2
!------------------------------------!
subroutine Sub3(y)
integer, intent(in) :: y
end subroutine Sub3
!------------------------------------!
end module Example
!----------------------------------------------------------------!
program prueba
use Example
implicit none
integer :: x
real :: y
complex :: z
call Generic_Sub(x)
call Generic_Sub(y)
call Generic_Sub(z)
end program prueba
!----------------------------------------------------------------!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Someone else reported it for you.
This program is illegal - the language does not allow a generic name to appear in a MODULE PROCEDURE declaration. "A module procedure is a procedure that is defined by a module subprogram (R213)." R213 says that a module-subprogram is either a function-subprogram or a subroutine-subprogram.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
>> Please report all such issues to Intel Premier Support. <<
Took note of that for the next time, thanks :-)
>> "A module procedure is a procedure that is defined by a module subprogram (R213)." <<
Thanks also for pointing me to that. I was looking into the Fortran95 standard without finding a clear answer and so I just tried it out.
Miguel
Took note of that for the next time, thanks :-)
>> "A module procedure is a procedure that is defined by a module subprogram (R213)." <<
Thanks also for pointing me to that. I was looking into the Fortran95 standard without finding a clear answer and so I just tried it out.
Miguel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So are you saying you cant overload an overloaded procedure? An indirect way of achieving such a result is to define a procedure procm in module m that calls the overloaded procedure procn. then one can overload procm onto anything else. of course it kind of defeats the purpose since multiple instances of procm may then be needed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can extend an existing generic by creating your own generic interface of the same name with an additional module procedure. The compiler will then merge them, assuming all of the specific procedures have unambiguous signatures. You don't do this by giving the generic name as a module procedure.
For example, say you had:
module a
interface foo
module procedure foo_int
end interface foo
contains
subroutine foo_int (arg)
integer arg
...
end subroutine foo_int
end module a
Now you can do this:
module b
use a
interface foo
module procedure foo_real
end interface foo
contains
subroutine foo_real (arg)
real arg
...
Get it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
>> You can extend an existing generic by creating your own generic interface of the same name with an additional module procedure. <<
Didn't know that. Very interesting. Is it something defined in the Fortran standard or an enhancement of the intel compiler?
The problem I'm trying to address cannot be solved with the above idea. It solves the example I have used, but not the real case :-(, where I need to not only extend a generic name, but also rename it.
Would it work if the generic interface to be renamed and extended would be in a different module and then rename it through the USE statement? In that case it should work, or?. I will try and let you know.
Miguel
Didn't know that. Very interesting. Is it something defined in the Fortran standard or an enhancement of the intel compiler?
The problem I'm trying to address cannot be solved with the above idea. It solves the example I have used, but not the real case :-(, where I need to not only extend a generic name, but also rename it.
Would it work if the generic interface to be renamed and extended would be in a different module and then rename it through the USE statement? In that case it should work, or?. I will try and let you know.
Miguel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It is a standard feature and it works (or is supposed to work, anyway!) with renaming. This is a part of the language that trips up a lot of compilers, so if you encounter problems, do let us know.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have tried the following example with total success :-):
!-------------------------------------------------------------!
module Original_One
implicit none
interface Original_Generic
module procedure Real_Values
module procedure Complex_Values
end interface
contains
!----------------------------------!
subroutine Real_Values(x)
real, intent(in) :: x
write(*,*) "Real"
end subroutine Real_Values
!----------------------------------!
subroutine Complex_Values(x)
complex, intent(in) :: x
write(*,*) "Complex"
end subroutine Complex_Values
!----------------------------------!
end module Original_One
!-------------------------------------------------------------!
module Extended_One
use Original_One, Extended_Generic => Original_Generic
implicit none
interface Extended_Generic
module procedure Integer_Values
end interface
contains
!----------------------------------!
subroutine Integer_Values(x)
integer, intent(in) :: x
write(*,*) "Integer"
end subroutine Integer_Values
!----------------------------------!
end module Extended_One
!-------------------------------------------------------------!
program Example
use Extended_One
implicit none
integer :: x
real :: y
complex :: z
call Extended_Generic(x)
call Extended_Generic(y)
call Extended_Generic(z)
end program Example
!-------------------------------------------------------------!
!-------------------------------------------------------------!
module Original_One
implicit none
interface Original_Generic
module procedure Real_Values
module procedure Complex_Values
end interface
contains
!----------------------------------!
subroutine Real_Values(x)
real, intent(in) :: x
write(*,*) "Real"
end subroutine Real_Values
!----------------------------------!
subroutine Complex_Values(x)
complex, intent(in) :: x
write(*,*) "Complex"
end subroutine Complex_Values
!----------------------------------!
end module Original_One
!-------------------------------------------------------------!
module Extended_One
use Original_One, Extended_Generic => Original_Generic
implicit none
interface Extended_Generic
module procedure Integer_Values
end interface
contains
!----------------------------------!
subroutine Integer_Values(x)
integer, intent(in) :: x
write(*,*) "Integer"
end subroutine Integer_Values
!----------------------------------!
end module Extended_One
!-------------------------------------------------------------!
program Example
use Extended_One
implicit none
integer :: x
real :: y
complex :: z
call Extended_Generic(x)
call Extended_Generic(y)
call Extended_Generic(z)
end program Example
!-------------------------------------------------------------!

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