Re: Returning a dynamic character array based on input length
  Home FAQ Contact Sign in
comp.lang.fortran only
 
Advanced search
POPULAR GROUPS

more...

 Up
Re: Returning a dynamic character array based on input length         

Group: comp.lang.fortran · Group Profile
Author: nospam
Date: Sep 10, 2008 17:07

GaryScott sbcglobal.net> wrote:
> Was curious as to how allocatable strings are likely implemented. A
> derived type with a length component and a string content component?
> Anything else (additional components)?

I think you are confusing a few things here.

First, they certainly aren't implemented as a derived type, insomuch as
that's a Fortran thing and there aren't currently any Fortran compilers
written in Fortran. (There have been in the past, and I'd think f2003 a
suitable language to write one in today, in fact that's an idea I've
toyed with, but there aren't any right now).

Second, the answer depends partly on context. Fundamentally, an
allocatable string needs a pointer to the dynamically allocated body and
an indication of the length. For an allocatable string standing alone,
that's pretty much all you need. There doesn't need to be any particular
structural relationship between the pointer and the length. Now if the
allocatable string is a component, then there needs to be a consistent
convention on how it is represented in the derived type. But that would
be for a component, not necessarily any allocatable string. "Obviously"
the derived type will have to have that pointer and length data; as to
whether it also has anything else, I'm not so equipped to say; it might
vary. Likewise, an allocatable dummy argument has to have the same data.
It seems a reasonable guess that the descriptor (that's one of the terms
often used for these things) for a dummy argument is likely to be a lot
like what is used for a structure component.

Note, by the way, that allocatable and pointer things in Fortran tend to
look pretty much identical at the implementation level. The difference
lies more in assumptions that the compiler can make about them
(aliasing, strides), and in things that the compiler is required to
handle (automatic allocation/deallocation/initialization/etc.) But if
you look at memory layout, they are probably the same.

--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
no comments
diggit! del.icio.us! reddit!

RELATED THREADS
SubjectArticles qty Group
Access 97 using ODBC returning SQL server ntext fields dont return the full datamicrosoft.public.sqlserver.odbc ·