Bug or user error?

Salvatore Filippone sfilippone@uniroma2.it
Tue May 17 14:09:00 GMT 2005


Hi there,
>From reading M&R it was my understanding that NULL() pointer
initialization are to be honoured after an ALLOCATE statement for
derived type components, even if they are nested. 
However I am getting a 'This should not happen' from the attached code. 
Is this a bug, or am I mistaken? 

Thanks
-- 
Salvatore Filippone -- sfilippone@NOSPAMuniroma2.it

--------------- tst1.f90--------------- 
module inner
  type inner_type
    integer, pointer     :: iv(:) => null()
  end type inner_type
end module inner

module outer
  use inner
  type outer_type
    type(inner_type), pointer :: dat=>null()
  end type outer_type
end module outer
  

program tst1
  use inner
  use outer

  type(outer_type)  :: v
  integer :: i,info
  integer, allocatable :: iv(:)
  integer, parameter   :: nmax=8*1024

  ! This is to put some garbage on the heap. 
  allocate(iv(nmax),stat=info)
  do i = 1, size(iv)
    iv(i) = i*i+nmax
  end do
  deallocate(iv)
  
  if (.not.associated(v%dat)) then 
    allocate(v%dat,stat=info)
    if (associated(v%dat%iv)) then 
      write(*,*) 'This should not happen'
    else
      write(*,*) 'Ok '
    endif
  endif
end program tst1

------------- output -----------
[sfilippo@localhost TEMP]$ gfortran -v 
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../gcc-4.1-20050515/configure
--prefix=/usr/local/gfortran
Thread model: posix
gcc version 4.1.0 20050515 (experimental)
[sfilippo@localhost TEMP]$ gfortran -o tst1  tst1.f90 
[sfilippo@localhost TEMP]$ ./tst1
 This should not happen
[sfilippo@localhost TEMP]$ 




More information about the Fortran mailing list