(j3.2006) IMPLICIT and IMPORT statements in BLOCK constructs
Robert Corbett
rpcorbett
Wed Oct 4 19:51:44 EDT 2017
The descriptions of IMPLICIT and IMPORT statements in 17-007r2
leave me confused.? The text does not appear to be correct for
BLOCK constructs.? I might be misreading some portion of the
text.? If so, I would appreciate correction.
References that follow are to 17-007r2 unless stated otherwise.
Consider the program
????? PROGRAM MAIN
??????? A: BLOCK
????????? X = 1.0
??????? END BLOCK A
??????? B: BLOCK
????????? PRINT *, X
??????? END BLOCK B
????? END
The named variable X is implicitly declared in the inclusive
scope that consists of the scoping units for the main program
and the two BLOCK constructs [14:36-39, 3.87 "inclusive scope"].
Supposed the statement IMPLICIT NONE is added to BLOCK A.? My
reading of 17-007r2 is that the program continues to be
conformant because the variable X is implicitly declared in
BLOCK B and the scope of X is the inclusive scope, which
includes BLOCK A.? Similarly, if the statement IMPLICIT NONE
is added to BLOCK B instead of BLOCK A, the program is
conformant because the implicit declaration of X in BLOCK A
applies within BLOCK B.
Suppose the statement IMPLICIT REAL(A-Z) is added to BLOCK A
and IMPLICIT INTEGER(A-Z) is added to BLOCK B.? My reading is
that the variable X would be implicitly declared in one of the
BLOCK constructs and that that declaration would apply within
the other BLOCK construct.? The conformance clause of the
standard [29:6-7, 4.2p1 "Conformance"] states that the program
must have "an interpretation according to this document".
It does not say a conformant program must have a unique
interpretation.
As currently specified, allowing IMPLICIT statements in BLOCK
constructs seems more likely to confuse users than help them.
The Fortran 2008 standard explicitly prohibits IMPLICIT
statements from appearing in BLOCK constructs
[(10-007r1)172:1-2, 8.1.4p1 "BLOCK construct"].
The use of IMPORT statements within BLOCK constructs also
confuses me.? The semantics of IMPORT statements [123:1-31,
8.8p1-5] are given in terms of their effects on host
association.? In Fortran 2008, host association does not apply
within BLOCK constructs [(10-007r1)443:27-28, 16.5.1.4p1
"Host association"].? Within a BLOCK construct, local
identifiers in the inclusive scope containing the BLOCK
construct are accessible because the scope of those local
identifiers includes the BLOCK construct.
In 17-007r2, the cited text from the Fortran 2008 standard is
changed to "A nested scoping unit has access to named entities
from its host as specified in 8.8." [518:7-8, 19.5.1.4p1
"Host association"].? The text specified in 8.8 does not
explain the interaction between host association and
inclusive scopes.
Consider the program
????? PROGRAM MAIN
??????? REAL :: X = 1.0
??????? A: BLOCK
????????? IMPORT, NONE
????????? PRINT *, X
??????? END BLOCK A
????? END
The scope of X includes the block. so the instance of X that
appears in the block is in scope.? My reading is that the
program is conformant, but I think users will find that
surprising.
As currently specified, allowing IMPLICIT statements in BLOCK
constructs seems more likely to confuse users than help them.
The Fortran 2008 standard explicitly prohibits IMPLICIT
statements from appearing in BLOCK constructs
[(10-007r1)172:1-2, 8.1.4p1 "BLOCK construct"].
The use of IMPORT statements within BLOCK constructs also
confuses me.? The semantics of IMPORT statements [123:1-31,
8.8p1-5] are given in terms of their effects on host
association.? In Fortran 2008, host association does not apply
within BLOCK constructs [(10-007r1)443:27-28, 16.5.1.4p1
"Host association"].? Within a BLOCK construct, local
identifiers in the inclusive scope containing the BLOCK
construct are accessible because the scope of those local
identifiers includes the BLOCK construct.
In 17-007r2, the cited text from the Fortran 2008 standard is
changed to "A nested scoping unit has access to named entities
from its host as specified in 8.8." [518:7-8, 19.5.1.4p1
"Host association"].? The text specified in 8.8 does not
explain the interaction between host association and
inclusive scopes.
Consider the program
????? PROGRAM MAIN
??????? REAL :: X = 1.0
??????? A: BLOCK
????????? IMPORT, NONE
????????? PRINT *, X
??????? END BLOCK A
????? END
The scope of X includes the block. so the instance of X that
appears in the block is in scope.? My reading is that the
program is conformant, but I think users will find that
surprising.
If I misread the draft standard, I welcome correction.? If I
read it correctly, I recommend restoring the ban on IMPLICIT
statements in BLOCK constructs.? Any use I can see for them is
outweighed by the problems they cause.
While banning IMPORT statements from BLOCK constructs would
eliminate the problems they cause, I do see cases where they
could be useful.? On the other hand, fixing the text to make
them work as users might expect appears difficult.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.j3-fortran.org/pipermail/j3/attachments/20171004/167844b9/attachment.html>
More information about the J3
mailing list