Re: Proper way to return a string



e p chandler <epc8@xxxxxxxx> wrote:

As I understand it, a character(*) function returns a character
variable whose length is fixed by its caller.

Correct. Returning variable-length character function results, where the
length is computed within the function, is *VERY* tricky. It is
impossible in f77. (Taking the same length computation and duplicating
it outside of the fucntion is "cheating" - that no longer counts as
doing the computation within the function). In f90, you can sometimes do
it with specification expressions. In f90, specification expressions can
do much more (notably because they can reference user-written pure
functions), but they can be very messy and sometimes inefficient.

Not until f2003, with allocatable character length, can you finally do
general cases "cleanly". (And I don't off-hand know of any compilers
that yet implement allocatable character length, though it is possible
that the newest versions of some compilers might be, at least soon).

--
Richard Maine | Good judgment comes from experience;
email: my first.last at org.domain| experience comes from bad judgment.
org: nasa, domain: gov | -- Mark Twain
.



Relevant Pages

  • Re: Hollerith data initialization
    ... It was removed from the standard in f77. ... Most f90 compilers continue to implement it, ... The replacement for Hollerith is character type. ...
    (comp.lang.fortran)
  • Re: Backslashes
    ... doesn't conform to the standard. ... compatibility with existing f77 compilers at the time). ... any special translation to visible characters the user has typed. ... impose a peculiar translation of a visible character, ...
    (comp.lang.fortran)
  • Re: Hollerith constants on a little endian machine
    ... (snip of code using Hollerith constants and CHARACTER variables.) ... code, the first time pre-f77 code ran into trouble on an f77 compiler, about 25 years ago. ... To me, the advice was clear, that Hollerith constant strings should be changed to 'ABC' strings, no later than when character declarations were added for the receiving variables. ... We did have f66 compilers which accepted the quoted strings before we had f77 compilers. ...
    (comp.lang.fortran)
  • Re: Direct Access input of newline characters
    ... Is there any way to get the newline character returned? ... However, this is still feasible with direct access, by using unformatted ... and compilers XLF 8.1 and current versions ...
    (comp.lang.fortran)
  • Re: Why does Fortran have FORMAT statements?
    ... about what compiler allegedly violates the standard in this way. ... Continuation of character strings is subtle in fixed format. ... Some compilers may interpret it that way, ... uses Format statements was that it was the only option for about half ...
    (comp.lang.fortran)