Print

Print


Clive Page said:
>On Tue, 22 Aug 2000, Malcolm Cohen wrote:
>
>> Moreover, string length is not generally known at compile-time, so the
>> compiler would not know which routine to call anyway!
>
>Yes, using the word "generally" in the strict mathematician's sense, but
>length is known at compile-time in many actual cases.

My Fortran (77) text manipulation code uses assumed-length character rather
a lot, indeed probably most of the time.  YCMV.

>Indeed your own
>compiler (NAG f95) diagnoses an error at compile-time when the actual
>argument of a procedure is shorter than the dummy one and the interface is
>explicit

Yes, and it will diagnose it at runtime if the length is not constant but
the actual is shorter than the dummy.

> (though it does not even seem to issue a warning when it is the
>other way around).

That is because it is perfectly legal and reasonably commonly used.

Which makes character length unreasonable to use for generic disambiguation.

>> You could use the allocatable components version, which does not suffer
>> from these memory leaks.
>
>I presume that this only works with a compiler with f2k extensions?

Well, I wouldn't put it quite like that.

It works on a compiler that implements the ISO Technical Report on
allocatable components etc.  This was published late 1998, so it is
not unreasonable to expect some compilers to have implemented it.

And the pointer version of the varying-string module (i.e. the one which
leaks memory) can be used on compilers with garbage collectors.  This is
becoming more common.

>It seems to me that Fortran as currently defined has a string type which
>is unfortunately semi-dynamic: if all string lengths were fixed at
>compile-time then one could indeed use them as a procedure disambiguator,

Ugh.  If they were fixed at compile-time they would be unusable!
One would not be able to write procedures that accept any length strings!

As I mentioned above, this would render a lot of my Fortran-77 text
manipulation code useless.  We did not even have user-defined generics
in F77, and being able to have them would be a pretty poor substitute
for assumed-length character - one of the great features of F77.

>on the other hand if they were fully dynamic then one would not need to
>disambiguate procedures on length at all.  As it is, there doesn't seem to
>be a good solution.

As far as procedures go I have to disagree entirely - there is no need for
any additional feature there.

I appreciate the desire to allocate strings of variable length, but OTOH
variable-length-string manipulation is exactly the functionality that the
varying-string standard is attempting to fill.  Even if we already had the
F2002 facilities to allocate strings of variable length, the varying-string
standard remains a more convenient method of string manipulation.

The unfortunate bit is that relatively few manufacturers have bothered with
any kind of support for the varying-string part of the Fortran standard;
one might draw the conclusion that there are relatively few users demanding
this feature.  (To have leak-free varying-strings one needs either to have
a garbage collector, allocatable components, or to build them in to the
compiler.  We've supported them, by virtue of having a garbage collector,
for some time).

Cheers,
-- 
...........................Malcolm Cohen, NAG Ltd., Oxford, U.K.
                           ([log in to unmask])


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%