initialization of local variables

I am using legacy fortran code in which there are local variables in subroutine. These variables are declared but sometimes they are used without being initialized first.

Is there any compiler option to initialize these local variables to 0 for integer or 0. for real? I use PVF fortran compiler.


Giang Nong

If you compile with


then local variables will be statically allocated, so they are
initially zero.

It also means that the variables keep the last value from the previous
call, and are not zero again upon entry.

As a programming practice, not a bad idea to run

gfortran -Wuninitialized foo.f90

and then initialize the variables found in the code. That way, the program
should run if the local variables are statically allocated or come off the stack.