APPLY - call arbitrary function with arbitrary arguments.

Alternate Entry Name: .APPLY

Usage:

B:
   retval = apply( function_ptr, arglist_ptr, nargs );
C:
   int apply(void *function_ptr, void *arglist_ptr,
             int nargs);

Where:

function_ptr
is the address of the function you want to call.
arglist_ptr
is a pointer to a list of arguments to be passed to the function.
nargs
gives the number of arguments which are in the argument list.
retval
is the value returned by the function which "function_ptr" points to.

Description:

APPLY constructs and executes a call to the specified function. The stack is set up correctly for the number of arguments 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:

error( args, arg1, arg2, arg3, arg4, arg5, arg6, arg7 )
  {
    /* print out message on teletype, then exit */
    extrn printf;
    .write( -4 );
    apply( &printf, &args, nargs() );
    exit(1);
  }

Note that you must declare "printf" in an "extrn" statement. B normally recognizes function names as external because they are immediately followed by a left parenthesis "(". In a case like this where there is no parenthesis after the function name, the name must be explicitly declared as external.

Copyright © 1996, Thinkage Ltd.