Assumed character length functions - PR15326

Tobias.Schlueter@Physik.Uni-Muenchen.DE Tobias.Schlueter@Physik.Uni-Muenchen.DE
Fri Jun 10 15:52:00 GMT 2005


Quoting Paul Thomas <Paul.Thomas@jet.efda.org>:
> There are three viable solutions, as far as I can tell: (i) Since the
> character string is passed by reference, the function could return the
> string length; (ii) The string length could be passed by reference instead
> of by value, as the second argument; or (iii) it could be passed by
> reference as another hidden argument.

There's a third option: make the function type a structure describing the
string, i.e. something like
struct char_with_len {
  char * string;
  int len;
}
and then do away with the hidden arguments.  This should even work for functions
with ENTRYs, as the allowed combinations of types are restricted enough,
unfortunately I can't say for sure because I don't have the standard at hand.

> (ii) and (iii) have the advantage of being relatively simple to implement. I
> prefer (ii) because it is slightly more elegant. I do not think that it has
> any unwanted side-effects and is compatible with every permutation of
> function invocation that I can think of.
>
> Does anybody have an opinion on this? OK to implement (ii)?

I believe (ii) would work as well, I don't think it would be necessarily easier
than my suggestion, though.

- Tobi




More information about the Fortran mailing list