check for uninitialized variables?
Tobias Burnus
burnus@net-b.de
Tue Mar 20 17:20:00 GMT 2007
Hi,
Vivek Rao wrote:
> Is there a gfortran compiler option to check for the
> use of uninitialized variables. If not, is anyone
> working on this? I think this is a very valuable
> feature in catching bugs.
>
The checking is done by the middle end of GCC, which currently only
works if one enables optimization.
Example:
program test
integer :: x, y
y = x * 5
end program test
gfortran -Wall -O test.f90
gives:
test.f90: In function 'MAIN__':
test.f90:3: warning: 'x' is used uninitialized in this function
It is planned that the warning also works without "-O", cf.
http://gcc.gnu.org/ml/gcc/2007-03/msg00637.html
Another possibility (and more reliable) would be run-time checks. Or to
auto-initialize real variables by NaN; if one now traps NaN
(-ffpe-trap=invalid), one has also a check.
Neither of these two is planned* for the near future.
Tobias
* As this is a volunteer project, there is no real planning. It depends
what the contributes think is most needed either for themselves or for
gfortran. Thus it is hard to predict which of the two is implemented -
and how soon.
More information about the Fortran
mailing list