[J3] Scope of an implicitly declared variable in a construct
Van Snyder
van.snyder at jpl.nasa.gov
Fri Jul 5 20:15:00 EDT 2019
I searched unsuccessfully for an answer to this question.
It's probably right where I looked (clause 19), but if it's there I
didn't find it.
If a variable appears only within a BLOCK construct, is its scope that
construct, or that construct's inclusive scope?
In particular, does it become undefined when execution of the construct
completes?
This came up in a case where a colleague was using a BLOCK construct as
a target for an EXIT statement, not as a device to declare a construct
variable. A variable was defined and referenced only within a DO
construct within the BLOCK construct. It was defined only if the index
variable of an outer DO construct, that enclosed the BLOCK construct,
had the value 1. At least one processor complained that when referenced
in the inner DO construct during iterations of the outer DO construct
after the first one, it was not defined. I.e., it's a construct entity
of the BLOCK construct.
do I = 1, ...
....
b:block
....
do J = 1, ...
if ( I = 1 ) x = 0.0
! references to X. Is it defined when I > 1?
if ( ... ) exit B
end do ! I
....
end block b
....
end do ! J
That processor was apparently assuming X was "an unsaved local variable
of a BLOCK" and applying 19.6.6p1(23).
My recommendation to my colleague was IMPLICIT NONE, but that doesn't
solve the problem in the standard (if there is one).
More information about the J3
mailing list