"Variable XXX is used before its value has been defined." Warning Activation

"Variable XXX is used before its value has been defined." Warning Activation

Is there a compiler option that will activate the "Variable XXX is used before its value has been defined" warning?

Here is the situation:
a = 1.0
z = 2.0
c = a + b

The "z" above is a typo. I really meant for it to be "b".

So because of thistypoinstead of getting c = 3.0, I will get c = 1.0.

I stillhave access to the old Compaq Visual Fortran v6.6 compiler. It issues the warning noted above, but I am unable to come up with a set of compiler options to force the warning in Intel Visual Fortran.

4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.


Try the run-time flag /check:uninit. This catches most, sadly not all, such situations. {Also try /Qtrapuv; this flag initializes stack variables to an unsual value. In your case, you will not get c = 1. Note, however, that this can not be relied upon as in some cases the values will not be sufficiently unusal or else will go un-noticed.}

It may be a good idea to add /check:all to catch other problems as well.


If z is not a valid variable in the subprogram, it is easy to catch if, instead of relying on implicit typing rules, you declare variables explicitly and impose IMPLICIT NONE (by adding this statement to every subprogram and block data, or using a compiler option, if provided).

Try enabling the sourcechecking (static verification) feature of Intel Visual Fortran:

Program uninit

a = 1.0

z = 2.0

c = a + b

print *, 'C=',c

end program uninit

>ifort /nologo /Qdiag-enable:sc3 uninit.f90

uninit.f90(3): warning #12178: this value of "Z" isn't used in the program

uninit.f90(4): error #12143: "B" is uninitialized

Run-time checking may be better for finding cases with more complex control flow. Currently, it only works for local, scalar variables (i.e., automatic scalar variables that are stored on the stack). I would certainly recommend /check:uninit over /Qtrapuv. For example,

>ifort /nologo /check:uninit /Qauto /traceback uninit.f90


forrtl: severe (193): Run-Time Check Failure. The variable 'UNINIT$B' is being

used without being defined

Image PC Routine Line Source

uninit.exe 00448EDA Unknown Unknown Unknown

uninit.exe 004043B0 Unknown Unknown Unknown

uninit.exe 00404B92 Unknown Unknown Unknown

uninit.exe 00401041 _MAIN__ 4 uninit.f90

uninit.exe 0044EE73 Unknown Unknown Unknown

uninit.exe 004336C7 Unknown Unknown Unknown

kernel32.dll 763A3677 Unknown Unknown Unknown

ntdll.dll 77EA9D72 Unknown Unknown Unknown

ntdll.dll 77EA9D45 Unknown Unknown Unknown

But I also agree with the suggestion to use IMPLICIT NONE and to declare all your variables explicitly.

Leave a Comment

Please sign in to add a comment. Not a member? Join today