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

ifort/ifx accepts invalid initialization of derived type in data statement using NULL()

Harald1
New Contributor II
690 Views

The following non-conforming code should be rejected by ifort/ifx, but currently is not:

program p
  type t
     integer :: a
  end type
  type(t) :: x
  data x /t(null())/
end

This is for

% ifort -V
Intel(R) Fortran Intel(R) 64 Compiler Classic for applications running on Intel(R) 64, Version 2021.2.0 Build 20210228_000000

Thanks,

Harald

 

1 Solution
Steve_Lionel
Honored Contributor III
676 Views

I agree that this is nonconforming, and no reasonable interpretation exists. NULL() is allowed to be used in DATA, but only when it corresponds to a POINTER.

View solution in original post

3 Replies
JohnNichols
Valued Contributor III
682 Views

 

  program p
  type t
     integer :: a
  end type
  type(t) :: x
  data x /t(null())/
  
  write(*,*)x%a
end

 

x%a is initialed to 0

0 Kudos
JohnNichols
Valued Contributor III
682 Views
program p
  type t
     integer :: a
  end type
  
  type ta
    real, pointer :: ptr => null()
  end type
  
  type(ta) :: xa
  
  type(t) :: x
  
  data x /t(null())/
  allocate(xa%ptr)
  
  
  write(*,*)x%a
end

xa%ptr is now a very small real -- LISP is nice it tells you the side effects. 

0 Kudos
Steve_Lionel
Honored Contributor III
677 Views

I agree that this is nonconforming, and no reasonable interpretation exists. NULL() is allowed to be used in DATA, but only when it corresponds to a POINTER.

Reply