Path: utzoo!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!ncar!ames!sgi!bron@bronze.SGI.COM From: bron@bronze.SGI.COM (Bron Campbell Nelson) Newsgroups: comp.lang.fortran Subject: Dubious Fortran Construct Keywords: DO loops; transfer of control Message-ID: <22994@sgi.SGI.COM> Date: 7 Dec 88 00:26:43 GMT Sender: daemon@sgi.SGI.COM Organization: Silicon Graphics, Inc., Mountain View, CA Lines: 33 A random question for you all: How does your Fortran compiler handle branches to a DO loop termination statement? In particular, in the following program, statement "10" terminates both DO loops, and is branched to by a statement in the outer DO loop: subroutine foo(a, b, n) real a(n), b(n,n) do 10 i = 1,n if (a(i) .eq. 0) goto 10 do 10 j = 1,n b(i,j) = 1/a(i) 10 continue return end I am aware that the VMS compiler rejects this as illegal since it considers statement 10 to belong to the inner loop, and so the branch would be into an inner block (which is illegal). A couple of variants of the f77 compiler I've dealt with accept the syntax without complaint, but generate bad code (i.e. if a(1) is zero, the loop iteration processing will attempt to examine the value of j, which is uninitialized at that point). The Fortran 77 standard seems a bit ambiguous (to me anyway) as to whether the above is legal. So the question is, do you think the above is legal? Does your compiler think so? -- Bron Campbell Nelson bron@sgi.com The opinions expressed are not necessarily those of the author's employer, are not necessarily those of the author's friends, are not necessarily even those of the author, and are probably not necessary.