Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Making DLL arguments part of a module

Pramod_V_
初学者
614 次查看

I am trying to make the arguments of a subroutine be part of the module so other subroutines can use it. Is there anyway to make this work without having to assign local variables (testDLL's a and b) to global variables (TestMod's a and b)? I am trying to avoid assignments as much as I can.

   module TestMod
      real :: a
      real :: b
      real :: c 
   contains
      !================================   
      subroutine testDLL ( a , b )
      implicit none
      !DEC$ ATTRIBUTES DLLEXPORT::TestDLL
         
      call otherSub1 ()

      end subroutine testDLL
      !================================
      subroutine otherSub1 ()
      
      implicit none
      
      c =  ( a + b ) * 5.0
      
      end subroutine otherSub1
   end TestMod

Thanks.

0 项奖励
1 解答
Steven_L_Intel1
614 次查看

No. Module variables are globals (and static), But you could do this:

module TestMod

contains
   !================================   
   subroutine testDLL ( a , b )
   implicit none
   !DEC$ ATTRIBUTES DLLEXPORT::TestDLL
      
   call otherSub1 ()

   contains
   !================================
   subroutine otherSub1 ()
   
   implicit none
   
   c =  ( a + b ) * 5.0
   
   end subroutine otherSub1

end subroutine testDLL
end TestMod

(I note that you don't declare c here, but you'll get the idea,) When testDLL calls otherSub1, any local variables in testDLL are visible in the contained subroutine otherSub1. Yes, you can have a contained procedure within a module procedure.

在原帖中查看解决方案

0 项奖励
1 回复
Steven_L_Intel1
615 次查看

No. Module variables are globals (and static), But you could do this:

module TestMod

contains
   !================================   
   subroutine testDLL ( a , b )
   implicit none
   !DEC$ ATTRIBUTES DLLEXPORT::TestDLL
      
   call otherSub1 ()

   contains
   !================================
   subroutine otherSub1 ()
   
   implicit none
   
   c =  ( a + b ) * 5.0
   
   end subroutine otherSub1

end subroutine testDLL
end TestMod

(I note that you don't declare c here, but you'll get the idea,) When testDLL calls otherSub1, any local variables in testDLL are visible in the contained subroutine otherSub1. Yes, you can have a contained procedure within a module procedure.

0 项奖励
回复