Recently, I met a bug caused by automatic initialization of Fortran's array (by IDE Visual Studio). So I coded a simple routine to give it a test :
SUBROUTINE test
IMPLICIT NONE
INTEGER :: a, u(2)
a = 1
WRITE(*,'(a,2i5)') 'original :', u(1), u(2)
u(1) = a + 1
WRITE(*,'(a,2i5)') 'after manip :', u(1), u(2)
END SUBROUTINE test
If we call this subroutine two times, like:
PROGRAM main
IMPLICIT NONE
INTEGER :: i
DO i=1,2
CALL test
END DO
END PROGRAM main
we will have the output like:
original : 0 0
after manip : 2 0
original : 2 0
after manip : 2 0
So we could find that even without initialization, array in fortran will be set to zero automatically. But if we do something to it's element, this element won't be eliminated from stack when the program quit the subroutine, and will be reserved and reused by the next call. Maybe this question is not of interest because it's recommanded to initialize variable.. But I am just curious of the mechanisme behind and wish exposing it to others Thanks in advance. DU