Automatic allocation of allocatable components of a type

forall
July 1, 2009 2:28 PM PDT
Rate
 
#3 Reply to #1
This is correct and a feature of Fortran 2003.

Another related feature of Fortran 2003 is for allocatable arrays, where you could say:

integer, allocatable, dimension(:) :: a

a = [3,4,5]
and a would get automatically allocated to the proper shape, deallocating any previous allocation.  In Intel Fortran, this behavior is NOT the default and requires an option /assume:realloc_lhs.   However, the use you described with the derived type components does not require the option.

Steve,

While obviously convenient - is this also not a bit dangerous?

What happens if you erroneously do something like

a=[3,4,5]

...
a=[3,4,5,10]

where the use of a 4-element array is a bug (lets say due to bug)

Then my understanding is that F-2003 reallocates array a "behind your back", which would make it harder to catch this bug. Conversely F-95 would generate an access error and you'd have a pretty clear indication of a bug.

I suppose this comes down to safety vs convenience, I am not really criticizing, just contemplating ;-)





Intel Software Network Forums Statistics

8473 users have contributed to 31605 threads and 100654 posts to date.
In the past 24 hours, we have 30 new thread(s) 110 new posts(s), and 160 new user(s).

In the past 3 days, the most popular thread for everyone has been gemm(A,A,A) like possible? The most posts were made to gemm(A,A,A) like possible? The post with the most views is Dear Steve, excuse me for a d

Please welcome our newest member Kevin Johnson