-qinitalloc

Category

Error checking and debugging

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

Read syntax diagramSkip visual syntax diagram
        .-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.

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