On Sep 14, 2004, at 12:07 PM, Aleksandar Donev wrote:
> Does the LEN parameter enter in generic resolution for character
> arguments in Fortran 95?
No way. It isn't in general known at compile-time. Generic resolution
is done at compile time. QED. I could go look up the exact details,
but it isn't really needed - you can just stop after noting the above
2 points unless you are trying to make sure that the standard actually
says it correctly.
> I have a generic, and one of the specific procedures is for character
> strings with LEN=1. Then I try to call this generic with a string of a
> different length. All compilers I have tried so far did not complain,
This has little to do with generics. Calling a procedure with an
incorrect
character length is illegal, but is among the kinds of things that many
compilers won't catch. Again, it is not in general detectable at
compile-time, though special cases are.
> but I am trying PGI now and it complains. Can I add a specific to the
> generic for arbitrary LENgth?
You can have a specific for an arbitrary length. In fact, I recommend
it.
Again, nothing to do with generic, but I recommend that *ALL* character
dummy arguments be declared with a length of * unless you have very
good and specific reasons otherwise. I *HAVE* seen subtle bugs caused
by calling with incorrect character lengths; memory gets overwritten,
etc.
That much is f77 stuff...in fact, that's where I saw the bugs because I
had trained myself to always use * length before f90 came around.
What you can't do is disambiguate based on the length. But you can have
a specific that accepts any length (by using len=8).
> In F2x I believe we changed this a bit as now a string can be
> associated
> with a character array, but am not sure if generic resolution has
> changed also or not?
Nope. See above. It can't. Generic resolution is still done at
compile
time and is thus fundamentally incompatible with disambiguation based
on string length. And string arrays don't make any difference in this
regard because you can't disambiguate based on array size either,
for exactly the same reason. You can disambiguate based on rank, but
not on size.
--
Richard Maine | Good judgment comes from experience;
[log in to unmask] | experience comes from bad judgment.
| -- Mark Twain
|