Varying length character strings by John Reid

Tobias Burnus burnus@net-b.de
Tue Jan 29 08:37:00 GMT 2013


John Chludzinski wrote:
> Should the code contained in:
> ftp://ftp.nag.co.uk/sc22wg5/N1901-N1950/N1913.txt be compilable using
> the gfortran compiler?

Eventually yes, but deferred-length/allocatable-length strings as 
components of derived types aren't yet supported; thus, the following fails:

type VARYING_STRING
   CHARACTER(LEN=:),ALLOCATABLE :: chars
end type VARYING_STRING

That's tracked at http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51976

Implementing it is not that simple as it requires some changes how to 
compiler internally handles string lengths.

(Note to gfortran developers: One issue is that the gfc_charlen (e.g. 
"ts.u.cl") is shared (cf. ts.u.cl->length->...->backend_decl). 
Additionally, the length will have to be something like 
"dt%comp%hidden_length_comp", i.e. "dt%comp%" has to be added at all 
places. A half-working version, which updates se.string_length is not 
that difficult, but some hard issues remain. Note 2: When implementing 
it, keep DT length-type parameter in mind, when used as 
"character(len=lenght_param) :: comp", the issues are nearly identical.)

> PURE FUNCTION s_to_c(string) ! generic CHAR
>   1
> Error: CHARACTER(*) function 's_to_c' at (1) cannot be pure

I think here the compiler confused character(len=*) with 
character(len=:); that has been fixed in GCC 4.8, but one runs into an 
internal compiler error:

foo.f90: In function 's_to_c':
foo.f90:5:0: internal compiler error: in gfc_add_modify_loc, at 
fortran/trans.c:159
      s_to_c = string
  ^
0x5b8e97 gfc_add_modify_loc(unsigned int, stmtblock_t*, tree_node*, 
tree_node*)
         ../../gcc/fortran/trans.c:158
0x5f3af0 alloc_scalar_allocatable_for_assignment
         ../../gcc/fortran/trans-expr.c:7629


The latter issue is now tracked at 
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56138

Tobias



More information about the Fortran mailing list