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

module can be included repeatedly?

Tai_Q_
Beginner
335 Views
module one 
integer, parameter::a=1
end module

module two
 
use  one

integer, parameter::b=2*a
end module

program main

use  two
use  one

print*, 'a=', a
print*, 'b= ',b

end program

The above code is fine for debugging and running. Pay attention that module one is both included in program main and module two. But this way of using module repeatedly is always oK?

0 Kudos
1 Solution
Steven_L_Intel1
Employee
335 Views

Yes, this is ok. It's interesting that you ask because I've been in discussion with others on the Fortran standards committee on this topic since I find that the standard is inappropriately vague on how "nested USE" works, with some words that contradict others. We know what we want it to say and I'm working on an "interpretation" to change the wording. Your use would continue to be fine, as long as all the "paths" to the ultimate declaration (parameter a in module one) have the same values for the VOLATILE and ASYNCHRONOUS attributes. (These are the only attributes that can be modified for a use-associated entity - and your PARAMETER can't have either of these anyway.)

View solution in original post

0 Kudos
2 Replies
jimdempseyatthecove
Honored Contributor III
335 Views

Consider

subroutine foo
  use SomeModule
...
end subroutine foo

subroutine bar
  use SomeModule
...
end subroutine bar

Is not some SomeModule used twice?

The compilation of a Fortran module creates two files: and Object file and a mod file. The object file (containing code and/or data) is linked once and the mod file is effectively used as a pre-compiled header (no object file code/data). The above sketch is not the same as the C/C++ static data and functions (as would be for #include ...). Therefore there is no conflict (only one instance of code/data from module being loaded).

Jim Dempsey

0 Kudos
Steven_L_Intel1
Employee
336 Views

Yes, this is ok. It's interesting that you ask because I've been in discussion with others on the Fortran standards committee on this topic since I find that the standard is inappropriately vague on how "nested USE" works, with some words that contradict others. We know what we want it to say and I'm working on an "interpretation" to change the wording. Your use would continue to be fine, as long as all the "paths" to the ultimate declaration (parameter a in module one) have the same values for the VOLATILE and ASYNCHRONOUS attributes. (These are the only attributes that can be modified for a use-associated entity - and your PARAMETER can't have either of these anyway.)

0 Kudos
Reply