problem with default initialized pointers in types?

Daniel Franke franke.daniel@gmail.com
Fri Dec 15 15:11:00 GMT 2006


Hi all.
It may be my code, but I have some strange problems lately. Please
consider types as:

TYPE :: pdb_record
  INTEGER     :: id
  [other members snipped]
END TYPE

TYPE :: pdb
  TYPE(pdb_record), DIMENSION(:), POINTER :: p => null()
  [other members snipped]
END TYPE

Also consider two subroutines as:

  SUBROUTINE pdb_init(this, ...)
    TYPE(pdb), INTENT(out)             :: this
    [code snipped]
    WRITE(*,*) ASSOCIATED(this%p), size(this%p)   ! last executable statement
  END SUBROUTINE

  SUBROUTINE pdb_write(this, ...)
    TYPE(pdb), INTENT(in) :: this
    WRITE(*,*) ASSOCIATED(this%p), size(this%p)       ! first
executable statement
    [code snipped]
  END SUBROUTINE

where pdb_init allocates and initializes THIS%P and pdb_write writes
the data to stdout. Now, the problem is: if THIS is passed to these
routines subsquently, e.g. like

  TYPE(pdb) :: pdbdata
  pdb_init(pdbdata, ...)
  pdb_write(pdbdata, ...)

the result from above write statements are:
 T          91              # end of pdb_init
 F           1               # start of pdb_write

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


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)?

Regards
       Daniel



More information about the Fortran mailing list