Intel® Fortran Compiler 16.0 User and Reference Guide
Lets you initialize a class of variables to zero or to signaling NaN.
[Q]init keyword snan: Not available on Intel® 64 architecture targeting the Intel® Xeon Phi™ coprocessor x100 product family (formerly code name Knights Corner)
Linux and OS X: | -init=keyword |
Windows: | /Qinit:keyword |
keyword |
Specifies the initial value for a class of variables. Possible values are:
|
OFF |
No initializations are performed by default if you do not specify any of these options. |
This option lets you initialize a class of variables to zero or to signaling NaN.
If you only specify option -init=zero or -init=snan (Linux* and OS X*) or /Qinit:zero or /Qinit:snan (Windows*), it affects only scalar variables. To apply the initialization to arrays as well, you must also specify option -init=arrays (Linux* and OS X*) or Qinit:arrays (Windows*).
If you specify both [Q]init snan and [Q]init zero, then certain variables of REAL and COMPLEX type are initialized to signaling NaN and certain variables of INTEGER and LOGICAL type are initialized to zero.
The following classes of variables are affected by the [Q]init option:
Variables of intrinsic numeric type, that is, of type COMPLEX, INTEGER, LOGICAL, or REAL, of any KIND
SAVEd scalar or array variables, not in the main program, that are not initialized in the source code
Local scalars and arrays
Module variables that are not initialized in the source code
Automatic arrays
Variables with the POINTER or ALLOCATABLE attribute
In a user-defined type, components that have the POINTER or ALLOCATABLE attribute may be initialized with option [Q]init
The following are general restrictions for this option:
[Q]init snan only affects certain variables of REAL or COMPLEX type.
You cannot initialize variables in equivalence groups to signaling NaN values.
In an equivalence group, if no member of that equivalence group has an explicit initialization or a default initialization (in the case of a derived type), a variable in that equivalence group can be initialized to zero.
Derived types, arrays of derived types, and their components will not be initialized.
Dummy arguments including adjustable arrays will not be initialized.
Variables in COMMON will not be initialized.
If you specify [Q]init snan, the floating-point exception handling flags will be set to trap signaling NaN and halt so that when such a value is trapped at run-time, the Fortran library can catch the usage, display an error message about a possible uninitialized variable, display a traceback, and stop execution. You can use the debugger to determine where in your code this uninitialized variable is being referenced when execution stops.
Setting the option [Q]init snan implicitly sets the option fpe 0. A compile time warning will occur if you specify both option fpe 3 and option [Q]init snan on the command line. In this case, fpe 3 is ignored.
If you build with optimization, the compiler may speculate floating-point operations, assuming the default floating-point environment in which floating-point exceptions are masked. When you add [Q]init snan, this speculation may result in exceptions, unrelated to uninitialized variables, that now get trapped. To avoid this, reduce the optimization level to /O1 or /Od (Windows*), or -O1 or -O0 (Linux* and OS X*) when doing uninitialized variable detection.
If you wish to maintain optimization, you should add option [Q]fp-speculation safe to disable speculation when there is a possibility that the speculation may result in a floating-point exception.
On Intel® 64 architecture targeting the Intel® Xeon Phi™ coprocessor x100 product family (formerly code name Knights Corner), you cannot specify [Q]init [no]snan, since trapping signaling snan is not available.
Use option [Q]save if you wish all variables to be specifically marked as SAVE.
Visual Studio: Data > Initialize Variables to Signaling NaN
Data > Initialize Variables to Zero
Data > Initialize Arrays as well as Scalars
Eclipse: None
Xcode: Data > Initialize Variables to Signaling NaN
Data > Initialize Variables to Zero
Data > Initialize Arrays as well as Scalars
None
The following example shows how to initialize scalars of intrinsic type REAL and COMPLEX to signaling NaN, and scalars of intrinsic type INTEGER and LOGICAL to zero:
-init=snan,zero ! Linux and OS X systems
/Qinit:snan,zero ! Windows systems
The following example shows how to initialize scalars and arrays of intrinsic type REAL and COMPLEX to signaling NaN, and scalars and arrays of intrinsic type INTEGER and LOGICAL to zero:
-init=zero -init=snan –init=arrays ! Linux and OS X systems
/Qinit:zero /Qinit:snan /Qinit:arrays ! Windows systems
To see an example of how to use option [Q]init for detection of uninitialized floating-point variables at run-time, see the article titled Detection of Uninitialized Floating-point Variables in Intel® Fortran, which is located in https://software.intel.com/articles/detection-of-uninitialized-floating-point-variables-in-intel-fortran