1

我有一个模块,它定义了一个类型,它的方法,以及其他一些与类型无关的方法。

module TypeDef
   type, public :: T
     ...
     contains
     ...
     procedure type_proc
   end type
   
   ...
   contains !module
   
    
   subroutine type_proc( this, ... )
      class(T), target :: this
      ...
      call gen_proc( arg_1, arg_n-1, this, arg_n+1 )
      ...
   end subroutine type_proc

   ...

   subroutine gen_proc( arg_1, ..., arg_n-1, tv, arg_n+1 )
      ! this is a general module routine.
      ! NOT type related
      implicit none
      ...
      class(T), pointer, intent(in) :: tv
      ...
      if ( cond ) tv%member = 0
      ...
   end subroutine gen_proc
end module
   

在给定的点上,我从一个变量调用type(T), public :: var它的成员方法type_proc(),它在其内部调用一个通用模块过程gen_proc()。在那里,对于某些情况,我可能需要更改调用方法树的 ACTUAL 对象的某些成员(即var)。为此,我将this其作为常量指针call gen_proc()传递给函数调用时传递其地址,并访问其成员。

但是,我得到了描述的错误。

如果我通过引用而不是作为 const 指针传递它,则相同。

我看不出我是否做错了什么。此处Intel Fortran 错误 #6633:实际参数的类型与虚拟参数的类型不同,存在类似的情况,但call发生在不同的程序单元中。

编辑 2

好的,这已按预期编译并运行..

module test

   type, public :: T

      real, allocatable :: m1(:)
      real, allocatable :: m2(:)
      integer :: may_change

      contains

      procedure :: t_proc
      procedure :: all_t
   end type

   private :: all_t


   contains



   subroutine t_proc( this, n )
      implicit none
      class(T), target :: this
      integer, intent(in) :: n

      call this%all_t( n )
      call gen_proc( n, this%m1, this%m2, this )
   end subroutine t_proc



   subroutine all_t( this, n )
      implicit none
      class(T) :: this
      integer, intent(in) :: n

      allocate( this%m1( n ) )
      allocate( this%m2( n ) )
   end subroutine

   


   subroutine gen_proc( n, m1, m2, Tt )
      implicit none
      integer, intent(in) :: n
      real, intent(in) :: m1(n), m2(n)
      class(T), intent(in), pointer :: Tt

      if ( .true. ) Tt%may_change = 1
      print *, ' may change = ', Tt%may_change
   end subroutine gen_proc
end module test



module varmod

   use test

   type(T), public :: var
end module varmod




program main
   
   use varmod, only: var
   implicit none
   integer, parameter :: n = 2

   var%may_change = 0
   call var%t_proc( n )
end program main

所以,甚至比以前更多,我不知道实际代码可能有什么问题......

4

0 回答 0