View Full Version : error FRT2529:
R. T. (Fortran Man)
08-25-2003, 09:56 PM
I am getting compiler error FRT2529 when I try to compile the following code with the Fortran for .NET compiler. The derived type definitions are identical in both program units. Why is this error happening?
program FRT2529
interface
subroutine READN(AllBranchs)
type :: BranchInfo
sequence
real :: S
end type BranchInfo
type (BranchInfo), pointer :: AllBranchs(:)
end subroutine READN
end interface
type :: BranchInfo
sequence
real :: S
end type BranchInfo
type (BranchInfo), pointer :: AllBranchs(:)
call READN(AllBranchs)
end
subroutine READN(AllBranchs)
type :: BranchInfo
sequence
real :: S
end type BranchInfo
type (BranchInfo), pointer :: AllBranchs(:)
return
end
Lahey Support
08-27-2003, 10:01 PM
This error occurs because of how Fortran for .NET implements derived types.
Since the subprogram contains a derived type dummy argument with the pointer attribute, an interface is required in the calling program. Fortran for .NET implements all derived types as class objects. Because the interface is defined in the calling program, the definition in the interface uses the class associated with the calling procedure as the base class of the derived type class. Within the subprogram, the derived type definition uses the class associated with the called procedure as the base class of the derived type class. This causes an argument mismatch, because the actual argument and the dummy argument belong to different classes.
To rectify this problem, put the derived type definition into a module, and use the module eveywhere the derived type definition is required:
module typedef_module
type :: BranchInfo
sequence
real :: S
end type BranchInfo
end module
program FRT2529a
use typedef_module
interface
subroutine READN(AllBranchs)
use typedef_module
Type (BranchInfo), pointer :: AllBranchs(:)
end subroutine READN
end interface
Type (BranchInfo), pointer :: AllBranchs(:)
call READN(AllBranchs)
end
subroutine READN(AllBranchs)
use typedef_module
Type (BranchInfo), pointer :: AllBranchs(:)
return
end
This makes a derived type definition that is independent of calling and called procedures. To take the next logical step down this path, the subroutine can also be placed into the module, which eliminates the need for a separate interface:
module m
type :: BranchInfo
sequence
real :: S
end type BranchInfo
contains
subroutine READN(AllBranchs)
Type (BranchInfo), pointer :: AllBranchs(:)
return
end subroutine
end module
program FRT2529b
use m
Type (BranchInfo), pointer :: AllBranchs(:)
call READN(AllBranchs)
end
vBulletin® v3.6.8, Copyright ©2000-2012, Jelsoft Enterprises Ltd.