GerritGroot
Technical User
Hi,
Imagine that I've got a SUBROUTINE with some local subroutines under a CONTAINS statement, like:
In that case, the global "i" exists in the local subroutine right?
If I accidently define "i" again, thinking that I'm dealing with a new local variable, my global variable i will change unintentionally.
Is there a way to make gfortran check for this by means of any compiler option?
Of course if I just use "i" locally, the compiler may never find out, but if I redeclare it like "INTEGER :: i", the compiler might be able to conclude that I'm mistaken (which is what happened here)
Thanks,
Gerrit
Imagine that I've got a SUBROUTINE with some local subroutines under a CONTAINS statement, like:
Code:
SUBROUTINE GlobalSub
IMPLICIT NONE
INTEGER :: i
i=1
CONTAINS
SUBROUTINE LocalSub
IMPLICIT NONE
INTEGER :: i
DO i=1,10,1
WRITE(*,*)'the global variable i shouldn't change due to the local i here, should it? But it does'
END DO
END SUBROUTINE LocalSub
END SUBROUTINE GlobalSub
In that case, the global "i" exists in the local subroutine right?
If I accidently define "i" again, thinking that I'm dealing with a new local variable, my global variable i will change unintentionally.
Is there a way to make gfortran check for this by means of any compiler option?
Of course if I just use "i" locally, the compiler may never find out, but if I redeclare it like "INTEGER :: i", the compiler might be able to conclude that I'm mistaken (which is what happened here)
Thanks,
Gerrit