problem with default initialized pointers in types?

Paul Thomas paulthomas2@wanadoo.fr
Sat Dec 16 01:44:00 GMT 2006


Daniel,

This

program daniel
  TYPE :: pdb_record
    INTEGER     :: id
  END TYPE
  TYPE :: pdb
    TYPE(pdb_record), DIMENSION(:), POINTER :: p => null()
  END TYPE
  TYPE(pdb) :: pdbdata
  call pdb_init(pdbdata)
  call pdb_write(pdbdata)
contains
  SUBROUTINE pdb_init(this)
    TYPE(pdb), INTENT(out) :: this
    allocate (this%p(1))
    this%p(1)%id = 99
    WRITE(*,*) ASSOCIATED(this%p), size(this%p)
  END SUBROUTINE
  SUBROUTINE pdb_write(this)
    TYPE(pdb), INTENT(in) :: this
    WRITE(*,*) ASSOCIATED(this%p), size(this%p)
  END SUBROUTINE
end program daniel

gives the result that you expect:
> Without the initialization of pdb%p to null(), the result is the expected
> T          91              # end of pdb_init
> T          91              # start of pdb_write
as does another brand of fortran compiler.
>
>
> Could someone comment on this? An inherent problem within my code?
> Some implication of the fortran standard or a problem in gfortran-svn
> (currently can't test with another compiler)?
>
I don't know Daniel.  I think that you are going to have to develop an 
example that reproduces the problem.

Best regards

Paul



More information about the Fortran mailing list