- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page