我正在使用ffcall(特别是ffcall的avcall包)库来动态地将参数推送到可变参数函数.即我们有
int blah (char *a, int b, double c, ...);
Run Code Online (Sandbox Code Playgroud)
我们希望用来自用户的值来调用此函数.为此,我们创建了该函数的avcall版本:
int av_blah (char *a, int b, double c, char **values, int num_of_values)
{
av_alist alist;
int i, ret;
av_start_int (alist, &blah, &ret); //let it know which function
av_ptr (alist, char*, a); // push values onto stack starting from left
av_int (alist, b);
av_double (alist, c);
for (i=0;i<num_of_values;i++)
{
// do what you want with values and add to stack
}
av_call (alist); //call blah()
return (ret);
}
Run Code Online (Sandbox Code Playgroud)
现在,我使用avcall的功能是:
int …Run Code Online (Sandbox Code Playgroud)