Re: Scope question (gfortran odd-man out)



In article <1183409425.977263.53210@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
awgreynolds@xxxxxxxxxxxxx writes:
Consider the following code fragment:

subroutine main
:
call internal
:
contains
subroutine internal
do i=...
if (...) return
enddo
end subroutine
end

Should the undeclared variable "i" be in the scope of "main", i.e.
should it have the right do loop value in "main" after the call?

Admittedly this is somewhat "sloppy" coding, but all the Fortran-95
compilers I use except Gfortran answer "yes" to the question.
Gfortran requires me to put an "integer i" declaration at the top of
main.

I think you'll need to show actual code because it works for
me (for some definition of 'works').

troutmask:kargl[233] cat k.f90
program a
call internal
print '(A,I0)', '6 --> ', i
contains
subroutine internal
do i = 1, 5
print '(A4,I0)', 'i = ', i
end do
end subroutine internal
end program a
troutmask:kargl[234] gfc -o z k.f90
troutmask:kargl[235] ./z
i = 1
i = 2
i = 3
i = 4
i = 5
6 --> 6



--
Steve
http://troutmask.apl.washington.edu/~kargl/
.



Relevant Pages

  • Re: archive object not work, please help
    ... bash-3.1$ cat refs_a.f90 ... write') refa ... write') refb ... bash-3.1$ gfortran -c refs_a.f90 ...
    (comp.lang.fortran)
  • Re: archive object not work, please help
    ... bash-3.1$ cat refs_a.f90 ... write') refa ... write') refb ... bash-3.1$ gfortran -c refs_a.f90 ...
    (comp.lang.fortran)
  • Re: calling C from fortran
    ... $ gcc -c operating_system.c ... USE statement at cannot follow attribute declaration ... while gfortran is 4.4 ....will you plz check thes? ... should compose a single instruction: ...
    (comp.lang.fortran)
  • Re: Aargh - cant get makefile to work in gfortran under WindowsXP
    ... I have Windows XP SP2. ... I am told by my IT friends that the cat command ... Does the make.exe program in gfortran ... The reason I ask all of this, rather than install cygwin or something ...
    (comp.lang.fortran)
  • Re: BIND(C) for dummy argument procedure
    ... Adding,BINCafter EXTERNAL does not help: IFORT like GFORTRAN do ... but I don't think the abstract interface ... I regard it as the analog of the type declaration ... g95 rejects it but gfortran accepts it: ...
    (comp.lang.fortran)