Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29001 Discussions

Allocated Array with Allocated elements

mattsdad
Beginner
319 Views

The manual says that when an array is allocated it is not initiallized.

I have several derived types with elements that are allocated arrays in them (call them the elements for the inner arrays). I have some allocated arrays of these derived types (call them the outer arrays). Do I have to initializethe elements for theinner arrays to specify that they are not allocated? If so, how?

If I create an 'Empty_Element' ofan inner derived type, and I initialize the outer array by setting:
Outer(I) = Empty_Element
will the asignment pick up the unassociated state of the elements for the inner arrays?

0 Kudos
1 Reply
Jugoslav_Dujic
Valued Contributor II
319 Views
For all allocatables, including the allocatable components of derived types, the standard (and associated TR15581) specifies that there are only two states: allocated and unallocated. This is in contrast to the pointers, which can be also undefined, which in layman terms means that they might appear to point somewhere, but that somewhere is not valid memory. Further, allocatables must be unallocated at the time of instantiation.

All of that means that you don't have to worry about their initial status; once you allocate the Outer array, all of the allocatable components of its elements are guaranteed to start their life as unallocated. IOW, it is the compiler must go through pains (rather than you) to ensure that all the array descriptors newly crated under the surface are properly initialized to unallocated state (i.e. have zero address and cleared the appropriate flag in the descriptor status word).

Please also see "default initialization" page in your compiler documentation; it normally makes life much easier.


0 Kudos
Reply