(GCOS8 only)
Alternate Entry Name: .APPLY
retval = apply( function_ptr, arglist_ptr, nargs );
double array[4];
"nargs" should be 8, since each double value takes two machine words.
"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".
#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.
Copyright © 1996, Thinkage Ltd.