- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
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
- Etiquetas:
- Intel® Fortran Compiler
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
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.
Enlace copiado
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
Yes, PUBLIC is the default. If you do not want that, you should use either the PRIVATE statement or PRIVATE attributes.
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
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.
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
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)
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
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.
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
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...
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
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.
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
If you want more namespace clarity the USE xxxx, ONLY: A,B,C syntax is helpful....

- Suscribirse a un feed RSS
- Marcar tema como nuevo
- Marcar tema como leído
- Flotar este Tema para el usuario actual
- Favorito
- Suscribir
- Página de impresión sencilla