next up previous contents
Next: Numerical Type Conversions Up: Intrinsic Functions Previous: Intrinsic Functions   Contents

Generic vs. Specific Functions

F90 intrinsic functions are usually generic; this means that they can accept arguments of different types and return a value appropriate for that type of argument. For example, ABS(x) accepts an INTEGER, REAL, DOUBLE PRECISION or COMPLEX argument x, and the returned value is of the same type as x. In addition to the generic name, there are also specific names which depend on the argument type. For example, IABS, ABS, DABS, CABS are the absolute value functions for INTEGER, REAL, DOUBLE PRECISION and COMPLEX type arguments.

Why does F90 allow for both generic and specific names? First, generic names are easier to remember and use. When we write

{}
abs(x)
we understand that the compiler checks the type of the argument x. If it is is integer, then the compiler will substitute ABS (the generic name) with a call to IABS (the specific name); and similar for other types.

However, there are situations when the name of the function is not followed by arguments. For example, we can write a user-defined plot subroutine, which takes an intrinsic function f(x), evaluates it at and plots the graph (x,f(x)). We will invoke our subroutine with, say,

{}
call my_plot( abs )
to plot (x,ABS(x)) for between and , and will invoke it as
{}
call my_plot( sin )
to plot (x,SIN(x)) for between and . F90 allows the use of function names (ABS, SIN) as arguments in (another) procedure call. In these instances, the intrinsic function name is not followed by arguments. The compiler does not know which absolute value function to use (will ABS be called with integer, real or complex arguments in MY_PLOT? What if MY_PLOT is in a different file, which is compiled separately?) In consequence, it is the user's responsability to replace the generic name with the secific one when the intrinsic function name is a procedure argument.


next up previous contents
Next: Numerical Type Conversions Up: Intrinsic Functions Previous: Intrinsic Functions   Contents
Adrian Sandu 2001-08-26