Default initialization for components

You cannot specify default initialization for an allocatable component. Allocatable components are always initialized to unallocated.

You can specify default initialization for a nonpointer component using an equal sign followed by a constant expression, or by enclosing an initial_value_list in slashes. Enclosing an initial_value_list in slashes can apply to components in a standard derived type declaration, or those within a record structure.

For pointer components default initialization, use an arrow (=>) and then a reference to the NULL intrinsic with no arguments. You can specify default initialization for zero or more components of a derived type, but it is not necessary for every component.

A data object has default initialization if any direct component of its type is initialized. IBM extension beginsSuch an object cannot be a pointee. For more information about pointees, see POINTER (integer) (IBM extension).IBM extension ends

If a nonpointer component is of a type that has default initialization, the default initialization specified for the component overrides the default initialization specified for the components of the type.

IBM extension begins You can use an object that has default initialization in a common block as an IBM extension. IBM extension ends

Unlike explicit initialization, the SAVE attribute is not implied by default initialization. IBM extension beginsThe -qsave=defaultinit option causes default initialization to imply the SAVE attribute.IBM extension ends

If a storage unit that is storage associated has default initialization, the objects or subobjects supplying the default initialization must be of the same type and type parameters, bounds, and supply the same value for that storage unit.

A direct component receives an initial value if you specify default initialization on the corresponding component definition in the type definition, regardless of the accessibility of that component.

For a data object that can undergo default initialization, its nonpointer components are either initially undefined, or their corresponding default initialization expressions define them. Its pointer components with default initialization have association status disassociated, and all other pointer components have association status undefined.

If a variable that has default initialization has static storage class, then default initialization occurs for that variable when your application executes.

If a variable that is a function result, an INTENT(OUT) dummy argument, or a local variable without the SAVE attribute has default initialization, then default initialization occurs when the procedure containing the variable's declaration executes.

Allocation of an object that has default initialization for a component causes the component to:
  • Become defined, if the component is a nonpointer
  • Become disassociated, if the component is a pointer.

In a subprogram with an ENTRY statement, default initialization occurs only for the dummy arguments that appear in the argument list of the procedure name the ENTRY statement references. If a dummy argument has the OPTIONAL attribute, default initialization occurs only if that dummy argument is present.

Module data objects of derived type with default initialization must have the SAVE attribute to be a candidate for default initialization.