Re: Statement function host association



On Wed, 19 May 2005 , "James Van Buskirk" <not_valid@xxxxxxxxxxx> wrote:

> Here is my version of this compiler torture test:
>
> program shared_implicit
> real x(3)
>
> x = (/(j,j=1,3)/)
> call inner_1
> contains
> subroutine inner_1
> implicit real(j)
> j = transfer(42,j)
> write(*,*) j
> call inner_2
> write(*,*) j
> end subroutine inner_1
> subroutine inner_2
> implicit character(j)
> j = transfer(17,j)
> write(*,*) j
> end subroutine inner_2
> end program shared_implicit
>
> Results: lf95 as expected, cvf prints out:
>
> 5.8854536E-44
> ?
> 5.8854536E-44
>
> and g95 refuses to compile. I didn't try on a recent version
> of g95, though.

This was part of a discussion regarding the scope of implied-DO variables.
(My news server has dropped the original article, so my position in the thread
for this reply is not correct..)

I sent James e-mail asking him what lf95 produced that he "expected", and he
replied with an elaboration as to why he thought this was correc t. I
responded to him on this, and James asked that I post the response to the
group. My response follows.

--

I'm astonished that none of the standards committee members pointed out that
this was the subject of the very first interpretation to F95 and was included
in Corrigendum 1.

The interpretation text is as follows:

NUMBER: 000001
TITLE: Visibility of a data object with statement scope
KEYWORDS: visibility, data object, statement scope, scope DEFECT TYPE: Erratum
STATUS: Included in corrigendum/complete

QUESTION:

Part 1:

Consider the following program:

MODULE mod
INTEGER, PARAMETER :: jmin(1:10) = (/ (i, i = 1, 10) /)
END MODULE

PROGRAM main
USE mod
INTEGER :: i

DO i = 1, 10
PRINT *, 'jmin(i) = ', jmin(i)
END DO

END PROGRAM

Some Fortran compilers consider the implied-DO variable I used in the module
to be visible to program units using the module and some Fortran compilers do
not consider the I to be visible to using program units.

Is an entity with statement scope in the specification part of a module
visible to a program unit using the module and accessing the public data of
the module as exemplified by the above example?

Part 2:

Consider the adaptation of the example program from Part 1:

MODULE mod
INTEGER, PARAMETER :: jmin(1:10) = (/ (i, i = 1, 10) /)
CONTAINS

SUBROUTINE one
i = 99 ! Is this a local or module variable?
! Compilers that export I probably say module
END SUBROUTINE

SUBROUTINE two
PRINT *, i
END SUBROUTINE

END MODULE

The module specification part uses the variable I as an implied-DO variable of
an array constructor. Module procedure ONE sets a variable named I to a
value.

Given:

* An implicitly declared data object in the module specification
part where the variable has statement scope, and

* An implicitly declared variable in a module procedure where the
variable has the same name as the variable described in the first
bullet of this list

is the variable in the module procedure a module variable (known to the entire
module and thus available outside the module) or is the variable local to the
module procedure?

ANSWER:
The implied-DO variable is not visible to the using program.
14.1.3 Statement Entities states, in part, that

The name of a variable that appears as the DO variable of an
implied-DO in a DATA statement or an array constructor has a
scope of the implied-DO list. It has the type and type
parameter that it would have if it were the name of a variable
in the scoping unit that includes the DATA statement or array
constructor and this type must be integer.

The words "would have if it were" were intended to convey the idea that the
existence of an array constructor or data implied-DO variable does not
actually cause an associated variable in the scoping unit to come into
existence.

Also, the following text appears in the same section (281:12-14):

If the name of a global or local entity accessible in the
scoping unit of a statement is the same as the name of a
statement entity in that statement, the name is interpreted
within the scope of the statement entity as that of the
statement entity.

The word "If" here implies that there need not be any such global or local
entity with the same name as that of the statement entity.

The first edit makes this clear. The second edit makes the same point for
FORALL statements and constructs.

EDITS:
Page 280, Clause 14.1.3, at the end of the first paragragh (280:44)
add:

The appearance of a name as the DO variable of an implied-DO in a
DATA statement or an array constructor is not an implicit
declaration of a variable whose scope is the scoping unit that
contains the statement.

Page 281, Clause 14.1.3, at the end of the second paragraph [281:4]
add:

The appearance of a name as an index-name in a FORALL statement or
FORALL construct is not an implicit declaration of a variable whose
scope is the scoping unit that contains the statement or construct.

SUBMITTED BY: Larry Rolison

HISTORY: 97-237 m143 submitted
00-158 m153 passed unanimously
00-254 m154 passed J3 letter ballot #2
00-Aug Oulu passed by WG5 {N1403}
00-Oct wg5 edits contained in corrigendum #1 {N1421}


Steve Lionel
Software Products Division
Intel Corporation
Nashua, NH

User communities for Intel Software Development Products
http://softwareforums.intel.com/
Intel Fortran Support
http://developer.intel.com/software/products/support/
.



Relevant Pages

  • FAQ 7.15 How do I create a static variable?
    ... with lexical variables, though. ... block, $count is defined at compile-time, but also goes out of scope at ... subroutine and the value it uses is defined at compile-time so the ... The perlfaq-workers, a group of volunteers, maintain the perlfaq. ...
    (comp.lang.perl.misc)
  • FAQ 7.15 How do I create a static variable?
    ... with lexical variables, though. ... block, $count is defined at compile-time, but also goes out of scope at ... subroutine and the value it uses is defined at compile-time so the ... The perlfaq-workers, a group of volunteers, maintain the perlfaq. ...
    (comp.lang.perl.misc)
  • FAQ 7.15 How do I create a static variable?
    ... with lexical variables, though. ... block, $count is defined at compile-time, but also goes out of scope at ... subroutine and the value it uses is defined at compile-time so the ... The perlfaq-workers, a group of volunteers, maintain the perlfaq. ...
    (comp.lang.perl.misc)
  • FAQ 7.15 How do I create a static variable?
    ... with lexical variables, though. ... block, $count is defined at compile-time, but also goes out of scope at ... subroutine and the value it uses is defined at compile-time so the ... The perlfaq-workers, a group of volunteers, maintain the perlfaq. ...
    (comp.lang.perl.misc)
  • Re: type/rank mismatch error
    ... | procedures that are *NOT* in the same scope as the USE statement. ... See host association. ... declaration overrides the host-associated declaration. ...
    (comp.lang.fortran)