------- Comment #1 from burnus at gcc dot gnu dot org 2008-12-17 09:46 ------- For completeness: The compile-time check works in gfortran character(len=10), target :: str character(len=5), pointer :: ptr ptr => str end Error: Different character lengths in pointer assignment at (1)
However, I start to wonder whether that is actually valid? I know that it is rejected (at compile time) by gfortran, ifort, NAG f95, g95, openf95, and sunf95. However, if I read 7.4.2 of the Fortran 2003 standard I cannot find the restriction. ifort prints: error #6795: The target must be of the same type and kind type parameters as the pointer. [PTR] And that is what I find in the standard: "C716 (R735) If data-target is not unlimited polymorphic, data-pointer-object shall be type compatible (5.1.1.2) with it, and the corresponding kind type parameters shall be equal." The type "character" is doubtlessly compatible with the type "character" and both kind type parameters are the same (namely "1" = default character). I cannot find any special case about the LENgth type parameter in that section. In Fortran 95 I also only read: "Constraint: The target shall be of the same type, kind type parameters, and rank as the pointer." I must miss something because it is extremely unlikely that all compiler get it wrong. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31822