Re: How to make a function work with different type and kind type argument

In article <g9p0s8$iif$1@xxxxxxxxxxxxxxxxxxxxxxxxx>,
Craig Powers <craig.powers@xxxxxxxxxxxxxxx> wrote:

deltaquattro wrote:

long time no hear :) sure, I thought of that, but that's not nearly as
generic as the original sin function. While sin(x) works with any of
them on any machine, "your" mysin(x) only works with the two KTPs
Single and Double. Clearly, overloading cannot obtain the same level
of generality, since even the number of available KTPs varies from
machine to machine. So, I was wondering how "complete" generality is
achieved in the intrisic functions, and if this can be replicated by
user-defined functions.

The processors are not actually that general. They know what the total
list of available KINDs are, and they provide overloads for all of them.
Since there is no possibility of the addition of additional KINDs,
they don't need to provide any more generality than that.

What Paul suggested is a manual way of achieving the same result.

There may be ways to address these kinds of problems with the new
levels of abstraction provided by f2008. However, the "traditional"
way to solve these kinds of portability problems is with
preprocessors. This works best (or at least it is easiest) when the
only change required to the code is in the declarations, not in the
data structures or algorithms. Basically you write a program that
in turn writes the fortran code. The preprocessor loops over all of
the allowed types (that you provide as input), it outputs all of the
different KIND versions of the specific routines, along with the
interfaces required to have generic functionality. One particularly
good preprocessor for this kind of stuff is filepp:

$.02 -Ron Shepard