Purpose
Initializes allocatable and pointer
variables that are allocated but not initialized to a specific value,
for debugging purposes.
The
-qinitalloc option
applies to the following uninitialized variables:
- Variables that have the ALLOCATABLE attribute
and are allocated using the ALLOCATE statement
- Variables that have the POINTER attribute
and are allocated using the ALLOCATE statement
Syntax
.-noinitalloc-----------------.
>>- -q--+-initalloc--+--------------+-+------------------------><
'-=--hex_value-'
@PROCESS:
@PROCESS INITALLOC[(hex_value)] | NOINITALLOC
Defaults
-qnoinitalloc
By
default, the compiler does not initialize allocated storage to any
particular value.
Parameters
- hex_value
- A one- to eight-digit hexadecimal number.
- If you do not specify a hex_value, the
compiler initializes the value of each byte of allocated storage to
zero.
- To initialize each byte of storage to a specific value, specify
one or two digits for the hex_value. If
you specify only one digit, the compiler pads the hex_value on
the left with a zero.
- To initialize each word of storage to a specific value, specify
three to eight digits for the hex_value.
If you specify more than two but fewer than eight digits, the compiler
pads the hex_value on the left with zeros.
- In the case of word initialization, if allocatable variables are
not a multiple of 4 bytes in length, the hex_value is
truncated on the left to fit. For example, if an allocatable variable
is only 1 byte and you specify five digits for the hex_value,
the compiler truncates the three digits on the left and assigns the
other two digits on the right to the variable.
- You can specify alphabetic digits as either uppercase or lowercase.
- For derived type variables with default initialization, initialization
with hex_value occurs before the default
initialization. See Example
2.
Usage
The
-qinitalloc option
provides the following benefits:
- Setting hex_value to zero (the default
value) ensures that all allocatable variables are cleared before being
used.
- You can use this option to initialize variables of real or complex
type to a signaling or quiet NaN, which helps locate uninitialized
variables in your program.
The usage of this option is similar to that of the -qinitauto option.
For more information, see -qinitauto.
Restriction: Objects that are equivalenced,
structure components, and array elements are not initialized individually.
Instead, the entire storage sequence is initialized collectively.
Examples
Example 1:
The following
example shows how the -qinitalloc option
works.
SUBROUTINE Sub()
REAL(4), ALLOCATABLE :: a, b
CHARACTER, ALLOCATABLE :: c
REAL(8), ALLOCATABLE :: d
ALLOCATE(a) ! a is allocated but not initialized.
ALLOCATE(b, SOURCE = 3.0) ! b is allocated and initialized to 3.0.
ALLOCATE(c)
ALLOCATE(d)
END SUBROUTINE
If you compile your program with
-qinitalloc=0cf,
for example, the compiler performs the following initialization:
- Pads 0cf with five zeros and initializes a to 000000CF
- Keeps the original initialization for b
- Truncates the first digit of 0cf and initializes c to CF
- Pads 0cf with five zeros, repeats the value,
and initializes d to 000000CF000000CF
Example 2:
The following
example shows how the -qinitalloc option
works when a derived type contains a component with default initialization.
TYPE dt
INTEGER :: i = 1 ! i has default initialization
INTEGER :: j
END TYPE
TYPE(dt), ALLOCATABLE :: dt1
ALLOCATE(dt1)
If you compile your program with -qinitalloc,
the compiler keeps the default initialization for i,
and initializes j to zero.
Related information
- The ALLOCATABLE attribute
in the XL Fortran Language
Reference
- The ALLOCATE statement
in the XL Fortran Language
Reference
- The POINTER statement
in the XL Fortran Language
Reference