Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can one variable-args function call another? [duplicate]

Tags:

c

Say you have 2 functions:

void func(int x,int y,...)
{
 //do stuff
}
void func2(int x,...)
{
 func(x,123,...);
}

How can you make this work, e.g pass the arg-list to the other function?

EDIT: this is a duplicate, can someone merge them or whatever?

like image 717
Mr. Boy Avatar asked Nov 11 '09 11:11

Mr. Boy


1 Answers

You need a separate version that works with explicit argument lists:

void vfunc(int x, va_list args)
{
  /* do stuff */
}

void func2(int x, ...)
{
  va_list arg;

  va_start(arg, x);
  vfunc(x, arg);
  va_end(arg);
}

This is the reason there are standard functions like vprintf().

like image 79
unwind Avatar answered Nov 20 '22 16:11

unwind