This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Does GFortran Report Use of Undefined Variables?
- From: "Craig Dedo" <craig at ctdedo dot com>
- To: "GNU Fortran" <fortran at gcc dot gnu dot org>
- Cc: "Craig Dedo" <craig at ctdedo dot com>
- Date: Mon, 16 Apr 2012 13:43:37 -0500
- Subject: Does GFortran Report Use of Undefined Variables?
Everyone:
Does GFortran report (i.e., generate error messages) references to undefined
variables during execution? If so, what command options do I need to use in order to get
GFortran to generate such error messages?
Recently, I worked on a program that had problems with variables being used before
they were defined. My copy of GFortran 4.7 for Windows did not catch these problems.
Instead, the programs built with GFortran went merrily on as if there was nothing wrong
and generated wrong results.
I compiled the program with another compiler and it generated a fatal error
message at the point of the usage of the undefined variable.
Here is a different, minimal example program. The main program and subroutines
are in separate files.
Subroutine Set_Common_Vars
Implicit None
Integer, Parameter :: Real64 = Selected_Real_Kind ( P=15, R=300 )
Real (Kind=Real64) :: A, B
Common / Common_Vars / A, B
B = 2 ! Oops! We forgot to set the value of A.
End Subroutine Set_Common_Vars
Program Undefined_Vars_Test
Implicit None
Integer, Parameter :: Real64 = Selected_Real_Kind ( P=15, R=300 )
Real (Kind=Real64) :: A, B
Common / Common_Vars / A, B
Real (Kind=Real64) :: C
!
! ***** START *****
! Execution starts here.
!
Call Set_Common_Vars
Write (*,*) "Calculate C, but A is undefined."
C = A + B ! B is defined with a known value, but A is undefined.
Write (*,*) "A = ", A, " B = ", B, " C = ", C
Write (*,*) "No error messages after referencing an undefined variable."
Stop
End Program Undefined_Vars_Test
Sincerely,
Craig T. Dedo
17130 W. Burleigh Place
P. O. Box 423??????????????????Mobile Phone:? (414) 412-5869
Brookfield, WI?? 53008-0423??? E-mail:? <craig@ctdedo.com>
USA
Linked-In:? http://www.linkedin.com/in/craigdedo