Martin Dix said:
> Please consider the following example
>
> module mod1
> integer :: n=1
> end module mod1
> module mod2
> use mod1
> integer :: m=2
> end module mod2
>
> program usetest
> use mod1, nx => n
> use mod2, nx => n
> integer :: n = 3
> print*, nx, m, n
> end program usetest
>
> In the main program n is accessible by use association from both modules
> mod1 and mod2 and conflicts with the local variable. Renaming these with
> something like
> use mod1, n1 => n
> use mod2, n2 => n
> is ok, but what about using the same name as in the example?
Seems ok.
> Two compilers I use accept this and one says it's an error. I've read
> section 11.2.1 of the F2003 draft standard and I'm not really any the
> wiser as to whether this is legal or not. It says that two or more
> accessible entities may not have the same name, but are these really
> different accessible entities or not?
What do you mean "these"? There is only one entity being accessed under
the name NX, and that is the entity N declared in the module MOD1.
You've accessed it twice, once directly and the other via MOD2, but it
is certainly the same entity you are accessing.
A very early F90 interpretation addressed this issue (with a more
complicated example):
--------------------------------------------------------------------------------
NUMBER: 000017
TITLE: Creation of entities by local names in rename-list
KEYWORDS: local name, use renaming
DEFECT TYPE: Interpretation
STATUS: Published
QUESTION: Does a local-name on a rename-list create a new data-entity? For
example, is the local name Q a new data entity or is Q a rename of the entity P
in the following example?
MODULE UTIL
PUBLIC P
CONTAINS
SUBROUTINE P
END
END MODULE UTIL
MODULE MID1
USE UTIL, Q=>P ! Is Q a new data entity or merely a
! renaming of P?
PUBLIC Q
END MODULE MID1
MODULE MID2
USE UTIL, Q=>P ! Another renaming of the same entity P?
PUBLIC Q
END MODULE MID2
SUBROUTINE ENDUSER
USE MID1
USE MID2
CALL Q ! Is this legal? Does it refer to P?
END SUBROUTINE ENDUSER
ANSWER: Multiple renames of the same <use-name> do not constitute separate
entities. Subsequent appearances of the <local-name> refer to the single
entity. In the example, Q does not create a new entity. Thus "CALL Q" in the
subroutine is legal.
Discussion: In section 11.3.2 [158:15-16], the standard states that a local name
in the rename list is a "local name for the entity" which is intended to mean
that a new entity is not created.
EDITS: None.
SUBMITTED BY: E. A. Johnson, 119-EAJ-1 (119.057)
HISTORY: 120-LF-1 (120.089)
077, ui 18 (jw note)
92-296 m123 Response proposed, approved by unanimous consent
N881 WG5 approval
--------------------------------------------------------------------------------
Cheers,
--
........................Malcolm Cohen ([log in to unmask]), Nihon NAG, Tokyo.
|