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

SIZE function on an ALLOCATABLE array

Jon_D
New Contributor II
960 Views

Hello,

The following code prints out 10 as the size of the ALLOCATABLE array after the array is deallocated. Is this the correct behavior or a compiler bug? I am using the latest version of the Intel Fortran compiler.

Thanks for any clarification.

PROGRAM Main
    IMPLICIT NONE
    
    INTEGER,ALLOCATABLE :: iTestArray(:)
    
    WRITE (*,*) SIZE(iTestArray)
    
    ALLOCATE (iTestArray(10))
    WRITE (*,*) SIZE(iTestArray)
    
    DEALLOCATE (iTestArray)
    WRITE (*,*) SIZE(iTestArray)
    
END

 

0 Kudos
2 Replies
Steven_L_Intel1
Employee
960 Views

It's your error for calling SIZE on an unallocated array. The result of that is undefined.

0 Kudos
andrew_4619
Honored Contributor III
960 Views

You should use the function allocated(itestarray)

0 Kudos
Reply