- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.)
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.)
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page