Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!
26758 Discussions

snan initialization for allocatable arrays

New Contributor I


Some time after this ( , IVF started to do NaN initial-value setting for allocatable arrays. 

The snippet below shows that allocatable arrays from type are not getting initialized. Is there anyway to do that?

The compile-line is: ifort /Od /debug:full /Qinit:snan /Qinit:arrays Test.f90

I am using Compiler 17.0 Update 4 with Visual Studio 2015.




      Module OM
         Implicit None
         Type newOBJ
            Integer :: j
            Real(8), Allocatable :: B(:)
         End Type newOBJ
         Subroutine SetObject(This)
            Type(newOBJ), Intent(OUT) :: This
            Allocate(This%B(2)) ! This won't initialize to NaN
         End Subroutine
      End Module OM
      Program Test
         Use OM
         Implicit None
         Real(8), Allocatable :: A(:)

         Type(newOBJ) :: OBJ
         Allocate(A(3)) ! gets initialized to NaN
         !Allocate(OBJ%B(2)) ! OBJ%B will get initialized to NaN
         Call SetObject(OBJ)
      End Program Test

0 Kudos
1 Reply

You've discovered a bug that still exists in the current release.

Please submit a bug report, which you can do by using the big orange button on the top of the main page of this forum.

To answer your question, you could create a variant of SetObject that accepts the component, and does the allocation.   For example:

         Subroutine SetObject2(This)            
            real(8), allocatable :: This(:)            
            Allocate(This(2)) ! This did initialize to NaN            
         End Subroutine

I did not try that with the 17.0 compiler, but it did work with our latest sources.