[J3] [EXTERNAL] Re: please try running this program
Clune, Thomas L. (GSFC-6101)
thomas.l.clune at nasa.gov
Mon Oct 24 15:12:38 UTC 2022
Bill,
The scoping rules affect whether or not all 3 X’s are the same. Printing 2 both times implies that all the X in the subroutines is the X in the main program. I’m not trying to follow the details, but I think the change Bob is referring to is that the new wording has X in the subroutines being local variables and thus you print 2 and then 1 when returning to the first procedure.
* Tom
From: "Long, Bill F" <william.long at hpe.com>
Date: Monday, October 24, 2022 at 10:36 AM
To: j3 <j3 at mailman.j3-fortran.org>, J3 List <j3 at j3-fortran.org>
Cc: "Clune, Thomas L. (GSFC-6101)" <thomas.l.clune at nasa.gov>
Subject: [EXTERNAL] Re: [J3] please try running this program
Cray gives 2. for both lines of output. As Tom points out, a RETURN statement does not belong in a man program. I removed it.
It is a feature of the Cray compiler that the kind vales for 32-bit real and integer are the same (4), though it is not a good idea to reply on that.
There are no IMPICIT statements in the program, so the default IMPLICIT mappings are in effect everywhere. I don't see how scoping rules are relevant here.
Cheers,
Bill
________________________________
From: J3 <j3-bounces at mailman.j3-fortran.org> on behalf of Clune, Thomas L. (GSFC-6101) via J3 <j3 at mailman.j3-fortran.org>
Sent: Monday, October 24, 2022 7:41 AM
To: General J3 interest list <j3 at mailman.j3-fortran.org>; J3 List <j3 at j3-fortran.org>
Cc: Clune, Thomas L. (GSFC-6101) <thomas.l.clune at nasa.gov>
Subject: Re: [J3] [EXTERNAL] please try running this program
Bob,
After removing the erroneous RETURN statement, I got 2.0000 for both prints from all 3 compilers that I tried (NAG, Intel, GNU).
· Tom
From: J3 <j3-bounces at mailman.j3-fortran.org> on behalf of j3 <j3 at mailman.j3-fortran.org>
Reply-To: j3 <j3 at mailman.j3-fortran.org>
Date: Monday, October 24, 2022 at 8:21 AM
To: J3 List <j3 at j3-fortran.org>
Cc: Robert Corbett <rpcorbett at att.net>
Subject: [EXTERNAL] [J3] please try running this program
PROGRAM MAIN
TYPE T
INTEGER(KIND(X)) Y
END TYPE T
CALL SUBR1
RETURN
CONTAINS
SUBROUTINE SUBR1
X = 1
CALL SUBR2
PRINT *, X
END SUBROUTINE SUBR1
SUBROUTINE SUBR2
X = 2
PRINT *, X
END SUBROUTINE SUBR2
END
The scope rules for implicit declarations
between Fortran 2008 with Corrigendum 1
and Fortran 2018. This program determines
which scope rules are used.
Robert Corbett
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20221024/8314cd02/attachment-0003.htm>
More information about the J3
mailing list