I have made this small test program to "prove" that you cannot use vectors without specifying their size prior to compilation (or if you make them allocatable). My point failed though. I was expecting that the local vector "num" would fail. The program cannot know the size of it before execution of the program. The size, nod, is read from the user at execution. I compile with the following command:
gfortan -fcheck=all test.f90
The value of "nod" was given as 500000000 during execution
The version of gfortran is 6.3.0
The execution went "fine" and returned the following answer:
7 9.9000000000000004 9.9000000000000004 500000000
So my question is; why doesn't the compiler throw errors to me that I'm writing outside a (non-defined) vector? I guess it sees my mistake and saves me?? By making it allocatable?? or am I totally wrong here?
MODULE globaldata
IMPLICIT NONE
INTEGER nod
END MODULE globaldata
MODULE modtest
USE globaldata
IMPLICIT NONE
CONTAINS
SUBROUTINE mysubtest(dummy)
IMPLICIT NONE
INTEGER :: dummy
REAL(kind=8) :: num(nod)
dummy = 7
num = 9.9d0
write(*,*) dummy,num(1),num(nod),size(num)
END SUBROUTINE mysubtest
END MODULE modtest
PROGRAM test
USE globaldata
USE modtest
IMPLICIT NONE
INTEGER dummy1
WRITE(*,*)"Give the value of nod:"
READ(*,*) nod
CALL mysubtest(dummy1)
END PROGRAM test