APPLY - call arbitrary function with arbitrary arguments.

(GCOS8 only)

Alternate Entry Name: .APPLY

Usage:

retval = apply( function_ptr, arglist_ptr, nargs );

Where:

type (*function_ptr)();
points to the function you want to call. The type of value returned by this function can be up to two machine words long.
void *arglist_ptr;
points to an array giving a list of arguments that should be passed to the function.
int nargs;
gives the length of the argument list in machine words. For example, if the argument list is
double array[4];

"nargs" should be 8, since each double value takes two machine words.

retval;
is the value returned by the function indicated by "function_ptr". This can have a length of up to two machine words.

Description:

"apply" constructs and executes a call to the specified function. The stack is set up correctly for the number of machine words given by "nargs". The arguments in the vector pointed to by "arglist_ptr" are passed to the function and the value which the function returns is returned to "retval".

"apply" is particularly useful for routines which are called with a variable number of arguments and which wish to pass these arguments on to another function. Note that you must pass the ADDRESS of the function you wish to call; thus if you wished to call "func" the argument you would pass would be "&func".

Examples:

#include <stdio.h>
#include <stdlib.h>
my_error( args, arg1, arg2, arg3, arg4, arg5, arg6, arg7 )
  {
    /* print out message on stdout, then exit */
    apply( &printf, &args, nargs() );
    exit(1);
  }

Note: this is just an artificial example. You would normally use the supplied "error" function for this purpose.

See Also:

expl nsc lib _vapply

Copyright © 1996, Thinkage Ltd.