4

I am working on a ~40 years old Fortran spaghetti code with lots of variables that are implicitly declared. So there is not a simple way to even know what variables exist in the code in order to initialize their values. Now, is there a way to tell the compiler (for example Intel Fortran) to initialize all variables in the code to a specific default value (e.g., -999) other than zero or a very large number, as provided by Intel compiler?

Scientist
  • 1,767
  • 2
  • 12
  • 20

2 Answers2

5

gfortran provides some options for this. Integers can be intialized with -finit-integer=n where n is an integer. For real numbers you can use -finit-real=<zero|inf|-inf|nan|snan>. Together with -ffpe-trap=denormal this can be very helpful, to get uninitialized reals.

Stefan
  • 2,460
  • 1
  • 17
  • 33
2

You probably want :

 ifort -check uninit

Note per the man page this only checks scalars

Also, based on some quick testing it is a pretty weak check. It doesn't catch this simple thing for example:

 program test
 call f(i)
 end
 subroutine f(j)
 write(*,*)j
 end

returns 0 ..

I suppose its better than nothing though.

agentp
  • 6,849
  • 2
  • 19
  • 37
  • 1
    More info about the weakness of this check: https://www.nas.nasa.gov/hecc/assets/pdf/training/UnInit_Fix_your_code_2012_10_31.pdf – astrojuanlu Jan 18 '16 at 15:31