- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I have stumbled about a non intuitive (at least for me) feature fo the Intel Compiler (2016 and 2017) which I am not sure is standard compliant or not.
If I have a type TT defined (as public) in a module M1, and that I do a USE M1 in a module M2, the type is then visible and useable in the module M2. This is clear to me. But if the module M2 does not use the PRIVATE keyword, using of M2 seems also to imply USE M1. Is it a behavior documented in the standard?
Here some simple code showing what I mean:
program Console use m2 implicit none type(TT) :: var ! Why can I use TT without a USE m1 ??? print *, 'Hello World' end program module m2 use m1 implicit none ! module is public end module module m1 implicit none private type, public :: tt end type end module
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When one module USEs another, all public entities of the USEd module become entities of the USEing module. If the default accessibility of that is PUBLIC, then all those use-inherited entities will also be PUBLIC. This is a fundamental aspect of Fortran and one that many applications depend on.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, PUBLIC is the default. If you do not want that, you should use either the PRIVATE statement or PRIVATE attributes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for your answer, I know that PUBLIC is the default. My question was specific to the recursion of USE statements: is it standard compliant that PUBLIC means also that USE is propagated? I thought that in order to use a public type in a subprogram, I had to make explicitely a USE of the module in which it is defined. Apparently you can also implicity use a type by using another module which is public.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
As far as I know it is standard-compliant. I have never seen it handled differently. It means that you use modules to bundle certain facilities and exclude unwanted ones without having to specify the exact list that you want in each and every program unit that uses them. (I have seen program code where there was a long list of all the modules that were used - just creating an overall module would have reduced such lists enormously)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When one module USEs another, all public entities of the USEd module become entities of the USEing module. If the default accessibility of that is PUBLIC, then all those use-inherited entities will also be PUBLIC. This is a fundamental aspect of Fortran and one that many applications depend on.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ok, that settles it then. I did not think it was the case, but it means than Fortran USEs behave a lot like an INCLUDE. What would be really nice would be the ability to specify that entities imported from a certain module should stay private to the USEing module...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There is: just use the PRIVATE statement and make only those entities PUBLIC that you want to be public. There is no difference in that respect for entities defined in the module itself or entities that were imported into that module via USE statements.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you want more namespace clarity the USE xxxx, ONLY: A,B,C syntax is helpful....
![](/skins/images/45C6C2D737ED71F4C51F0145C8CB1E9C/responsive_peak/images/icon_anonymous_message.png)
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page