Was always puzzled why this is allowed only if you set variable i as a PARAMETER and not as regular variable?
integer :: i = 1
integer :: j = 1-i
*** Error 538: I is not a PARAMETER, so cannot appear in an initialisation expression
Welcome to our forums
Was always puzzled why this is allowed only if you set variable i as a PARAMETER and not as regular variable?
integer :: i = 1
integer :: j = 1-i
*** Error 538: I is not a PARAMETER, so cannot appear in an initialisation expression
In Fortran, only constant expressions are allowed in an initialization expression.
A constant expression can comprise of:
Such expressions are evaluated at compile time and not at run time. Only parameters are known at compile time.
If Fortran allowed variable-dependent initialization, it would lead to undefined behavior because the compiler wouldn't know the correct value at compile time.