PDA

View Full Version : Generic Interface


blauwra1
03-11-2004, 02:22 AM
Has anyone had success spreading the definition of a generic interface across multiple files and modules? I have the situation (simplifying tremendously):

***file1:

module mod1

type type1
real(8) :: data1
real(8) :: data2
end type type1

interface init
module procedure type1_init
end interface init

contains

subroutine type1_init(obj,data1,data2)
type(type1) :: obj
real(8) :: data1
real(8) :: data2

obj%data1 = data1
obj%data2 = data2

end subroutine type1_init
end module mod1

***file2:

module mod2
use mod1

type type2
type(type1) :: obj1
type(type1) :: obj2
end type type2

interface init
module procedure type2_init
end interface init

contains

subroutine type2_init(obj,data1,data2)
type(type2) :: obj
real(8) :: data1
real(8) :: data2

call init(obj%obj1,data1,data2)
call init(obj%obj2,data2,data1)

end subroutine type2_init
end module mod2

--------------------------------------------
When I tried something like this on LF95 v6.1 on Linux I got an error about needing procedures specified in a generic interface to be all functions or all subroutines. I was porting this code from CVF 6.6C on Windows, where it compiled. No warnings were given there about this when I turned on F95 standard checking.

Thanks in advance for any suggestions,

Ross Blauwkamp
r.blauwkamp@ieee.org

blauwra1
03-11-2004, 04:32 PM
The example I gave earlier as a simplification does compile under LF95. Sorry about that. In the real code I did find that in one of the files the init generic interface specified a function, not a subroutine. CVF never complained and did run correctly, even with standard checking turned on. After downloading the standard (September 23, 2002), I found:

"Within a scoping unit, two procedures that have the same generic name shall both be subroutines or both be functions, ..."