Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Harald1
Novice
84 Views

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

Jump to solution

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
Black Belt Retired Employee
70 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 I
76 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

JohnNichols
Valued Contributor I
76 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. 

Steve_Lionel
Black Belt Retired Employee
71 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

Reply