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

Making DLL arguments part of a module

Pramod_V_
Beginner
615 Views

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 Kudos
1 Solution
Steven_L_Intel1
Employee
615 Views

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.

View solution in original post

0 Kudos
1 Reply
Steven_L_Intel1
Employee
616 Views

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 Kudos
Reply