-qinitauto

Category

Error checking and debugging

@PROCESS

None.

Purpose

Initializes uninitialized automatic variables to a specific value, for debugging purposes.

Syntax

Read syntax diagramSkip visual syntax diagram
        .-noinitauto-----------------.   
>>- -q--+-initauto--+--------------+-+-------------------------><
                    '-=--hex_value-'     

Defaults

-qnoinitauto

By default, the compiler does not initialize automatic storage to any particular value. However, it is possible that a region of storage contains all zeros.

Parameters

hex_value
A 1 to 8 digit hexadecimal number.

Usage

This option helps you to locate variables that are referenced before being defined. For example, by using both the -qinitauto option to initialize REAL variables with a NaNS value and the -qflttrap option, it is possible to identify references to uninitialized REAL variables at run time. Prior to XL Fortran Version 5.1.1, you could only use this option to initialize each byte of storage.

Setting hex_value to zero ensures that all automatic variables are cleared before being used. Some programs assume that variables are initialized to zero and do not work when they are not. Other programs may work if they are not optimized but fail when they are optimized. Typically, setting all the variables to all zero bytes prevents such runtime errors. It is better to locate the variables that require zeroing and insert code in your program to do so than to rely on this option to do it for you. Using this option will generally zero more things than necessary and may result in slower programs.

To locate and fix these errors, set the bytes to a value other than zero, which will consistently reproduce incorrect results. This method is especially valuable in cases where adding debugging statements or loading the program into a symbolic debugger makes the error go away.

Setting the hex_value to FF (255) gives REAL and COMPLEX variables an initial value of "negative not a number", or NaNQ. Any operations on these variables will also result in NaNQ values, making it clear that an uninitialized variable has been used in a calculation.

This option can help you to debug programs with uninitialized variables in subprograms. For example, you can use it to initialize REAL variables with a NaNS value. You can initialize 8-byte REAL variables to double-precision NaNS values by specifying an 8-digit hexadecimal number, that, when repeated, has a double-precision NaNS value. For example, you could specify a number such as 7FBFFFFF, that, when stored in a REAL(4) variable, has a single-precision NaNS value. The value 7FF7FFFF, when stored in a REAL(4) variable, has a single-precision NaNQ value. If the same number is stored twice in a REAL(8) variable (7FF7FFFF7FF7FFFF), it has a double-precision NaNS value.

Restrictions

Equivalenced variables, structure components, and array elements are not initialized individually. Instead, the entire storage sequence is initialized collectively.

Examples

The following example shows how to perform word initialization of automatic variables:
subroutine sub()
integer(4), automatic :: i4
character, automatic :: c
real(4), automatic :: r4
real(8), automatic :: r8
end subroutine
When you compile the code with the following option, the compiler performs word initialization, as the hex_value is longer than 2 digits:
-qinitauto=0cf
The compiler initializes the variables as follows, padding the hex_value with zeros in the cases of the i4, r4, and r8 variables and truncating the first hexadecimal digit in the case of the c variable:
Variable Value
i4 000000CF
c CF
r4 000000CF
r8 000000CF000000CF

Related information