(j3.2006) (SC22WG5.4609) Is this obscure USE usage legal?

Bill Long longb
Fri Dec 16 14:19:31 EST 2011



On 12/16/11 7:05 AM, N.M. Maclaren wrote:
> This arose on the gfortran mailing list.  I am 90% sure that there is a bug
> in both gfortran and Intel, especially as Sun, Pathscale and NAG all accept

Cray as well.

If I append a main program

program test
   call sub1
   call sub2
end program test

then execution gives

 > ./a.out
             2
             2

> this code.  But I am only 90% sure, as it all hangs on exactly which
> scoping unit the word 'local' applies to WHILE processing recursive
> inclusion!  Until this moment, it had never crossed my mind to query that.
>

Not really "recursive" inclusion, in the sense of an include line. The 
variable declared with the name axx in mod1 is accessible from either 
module.  It is allowed to have more than one local name (in sub1, for 
example). See [274:4] which says "An accessible entity in the referenced 
module has one or more local identifiers." (followed by a list of naming 
mechanisms). The "or more" is the key here.   In sub1, the variable is 
accessible from mod1 with the local name oxx ( second bullet - 
[274:7-8]) and also accessible from mod2 with the local name axx (third 
bullet - [274:9-10]).   Since there is no rename or only clause in the 
"use mod1" in mod2,  and neither module as any PRIVATE declarations, the 
variable and name axx have equal accessibility status from either 
module.  There is no basic difference between sub1 and sub2.

Cheers,
Bill



> Please tell me if I have missed something.
>
> Regards,
> Nick Maclaren.
>
>
>
> module mod1
> integer :: axx=2
> end module mod1
>
> module mod2
> use mod1
> end module mod2
>
> subroutine sub1
> use mod1, oxx=>axx
> use mod2
> implicit none
> print*,axx   !line compiles OK for gfortran, fails for Intel
> end subroutine sub1
>
> subroutine sub2
> use mod2
> use mod1, oxx=>axx
> implicit none
> print*,axx  !line fails to compile for gfortran, OK for Intel
> end subroutine sub2
>
> _______________________________________________
> J3 mailing list
> J3 at j3-fortran.org
> http://j3-fortran.org/mailman/listinfo/j3

-- 
Bill Long                                           longb at cray.com
Fortran Technical Support    &                 voice: 651-605-9024
Bioinformatics Software Development            fax:   651-605-9142
Cray Inc./Cray Plaza, Suite 210/380 Jackson St./St. Paul, MN 55101





More information about the J3 mailing list