This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Official Fortran standards
- From: Tim Prince <tprince at computer dot org>
- To: "Maciej Z. Pindera" <mzpnet at directvinternet dot com>, gcc at gcc dot gnu dot org
- Date: Tue, 18 Jun 2002 21:05:30 -0700
- Subject: Re: Official Fortran standards
- References: <3D11473B.5060903@directvinternet.com>
- Reply-to: tprince at computer dot org
On Wednesday 19 June 2002 20:08, Maciej Z. Pindera wrote:
> Hello,
>
> A quick Fortran question that hopefully is appropriate to this group.
> It concerns the official
> status on a DO loop index once the loop is finished. Specifically,
> given the following:
>
> program test
> implicit none
> integer i,n
> n=10
>
> do i=1,n
> arbitrary code
> enddo
>
> write(6,*)i
> stop
> end
>
> What do the Fortran standards say regarding the status of "i" at the
> "write" statement?
> I have come across some discussions that claim that according to the
> standards, "i" is undefined.
> If that is true, would it still be true even if "i" was formally
> adeclared an integer as in above?
> I realize that in many cases things like that depend on the compiler
> implementation. G77 in the GCC bundle gives i=n+1.
> I'd appreciate any info., chapter and verse if possible. Many thanks,
>
> Maciej
Prior to the f77 standard, i was undefined. This was one of the last points
on which compilers held out against that standard. I used compilers which
violated it, up to 10 years ago. Up to 15 years ago, I used a compiler
(which claimed only f66 compliance) where the same loop could produce 3
different results, according to the level of optimization.
I'm looking at ISO 1539-1980. I find it legalistically unclear as to whether
the DO parameter is defined subsequent to leaving the loop, except for the
one example which states that it is. The standard also states that the
parameter is incremented [by 1, if no increment is specified] before
decrementing the iteration count (11.10.7 (2) and (3)).
Anyway, g77 and all recent compilers behave as you have seen, unless possibly
you have invoked one of those options which alters the DO loop syntax to
correspond with some pre-77-standard compiler.
--
Tim Prince