> I'm sorry, but that's not what I mean... Clearly, you can have two
> functions/routines, put them in an interface block directly or through the
> MODULE PROCEDURE statement, and have the compiler pick among them by
> "disambiguating" based upon the kinds of the arguments being passed in and
> the kinds of the dummy arguments waiting to receive them in the procedure.
> The compiler swaps the generic name sin() for sin_single_precision, and away
> we go - compile-time polymorphism.
>
> But what Van Snyder said was that he had a _single version_ which he wrote
> for all kinds and selected internally. That's at least what I understood.
I think Alvaro missed one critical point. My "single version" is in an
include file, with declarations that depend on a kind type parameter that is
set before the include. This lets me write the procedure body once; the
processor compiles it twice -- once with kind(0.0e0), once with kind(0.0d0).
Of course, the whole procedure isn't in the include file. I put the
procedure header and the declaration of the kind type parameter in the
module -- once for single, once for double -- and everything else in the
include file. This is about the best I can do with Fortran 95, as far as
not duplicating effort. Sometimes, I can't even do that well. For example,
for my sort routine, to create one for two kinds of real and one kind of
integer, I have to declare some dummy arguments, and several local variables,
before the include.
--
Van Snyder | What fraction of Americans believe
[log in to unmask] | Wrestling is real and NASA is fake?
Any alleged opinions are my own and have not been approved or disapproved
by JPL, CalTech, NASA, Sean O'Keefe, George Bush, the Pope, or anybody else.
|