Hi, I am looking for a intel fortran compiler flag that would allow me to default initialize variables to 0 (or other values), these variables could be declared on the stack, the heap or allocated dynamically. I didn't find anything myself from the compiler options.
real :: x
real(:), allocatable :: y
With the default initialization, I am hoping I could initialize x and y to 0 during run time without manually initializing them. Is this possible through compiler flags?
Compiler option /Qzero
implicit initialization to zero of local scalar variables of intrinsic type INTEGER, REAL, COMPLEX, or LOGICAL that are saved and not initialized
Compiler option /Qinit:<keyword>
enable/disable(DEFAULT) implicit initialization of local
variables of intrinsic type INTEGER, REAL, COMPLEX, or
LOGICAL that are saved and not initialized
The <keyword> specifies the initial value
keywords: zero (same as /Qzero),
snan (valid only for floating point variables),
infinity, minus_infinity (valid only for floating point)
tiny, minus_tiny (valid only for floating point)
For allocatables use SOURCE with scalar
allocate(Y(10), SOURCE=0.0) ! or whatever value you want
Thanks, this is to help to identify the bug in the code and fix the problem. Occasionally we have legacy code where someone forgot to default initialize variables and it's difficult to pinpoint where the problem is. Being able to default initialize variables to 0 or infinity will help us to figure out where the problem is.
Jim, the -init option looks like exactly what I need.
>>Being able to default initialize variables to 0 or infinity will help us to figure out where the problem is.
Also consider using /Qtrapuv trap uninitialized variables
And /RTCu report use of variable that was not initialized
Relying on default initialization will get you into trouble, either sooner or later. Explicitly perform your initialization.
Implicit initialization is .NOT. part of the Fortran standard.
And why would you presume 0/0.0 is the proper value for initialization?
While you are at it, add
Note, warnings may be errors (in particular interface warnings).
Consider each warning before you dismiss it.
You don't need /gen-interface anymore if /warn:interfaces is enabled (or /warn:all).
I also like to do a build with /stand (standards checking) to identify extensions I hadn't intended to use - these can sometimes lead to unanticipated results.