Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
3 Views

module can be included repeatedly?

Jump to solution
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

Accepted Solutions
Highlighted
3 Views

Yes, this is ok. It's

Jump to solution

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.)

Retired 12/31/2016

View solution in original post

0 Kudos
2 Replies
Highlighted
3 Views

Consider

Jump to solution

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
Highlighted
4 Views

Yes, this is ok. It's

Jump to solution

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.)

Retired 12/31/2016

View solution in original post

0 Kudos