Alternate Entry Name: .APPLY
B: retval = apply( function_ptr, arglist_ptr, nargs );
C: int apply(void *function_ptr, void *arglist_ptr, int nargs);
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".
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.