type kva_arg(
kva_list vararg_list,
type)
In standard C, arguments that are char or short are converted to int and should be accessed as int. Arguments that are unsigned char or unsigned short are converted to unsigned int and should be accessed as unsigned int. Arguments that are float are converted to double and should be accessed as double.
none
Example variable argument routine definition:
var_arg_routine(int p1, int p2, double pN, kva_alist) { short var; // the next parameter after pN // is expected to be short kva_list *vararg_list; // the variable argument list
kva_start(vararg_list, pN); // pN is the last parameter // before variable args begin : var = kva_arg(vararg_list, short); : kva_end(vararg_list); }
The execution stack when procedure var_arg_routine is executed; before kva_arg is called, the "vararg_list" pointer is set to the address indicated below. | byte0 int parameter p1 | : | byte4 int parameter p2 | : | byte8 double parameter pN | : args stack address ---->| byte16 short parameter A "vararg_list" | byte17 | byte18 int parameter B | byte19 | byte20 | byte21 | :
Now, a call to kva_arg(vararg_list, short) moves the "vararg_list" pointer to byte18, and returns the pointer to byte16 as a short, so that var_arg_routine() can obtain the value of short parameter A.
the resulting execution stack is now: | byte0 int parameter p1 | : | byte4 int parameter p2 | : | byte8 double parameter pN | : args stack address -+ | byte16 short parameter A "vararg_list" | | byte17 (assigned to "var") +-->| byte18 int parameter B | byte19 | byte20 | byte21 | :
none
none
$BOOTSTRAP/include/kutils/kvarargs.h