Link to home
Start Free TrialLog in
Avatar of bganoush
bganoush

asked on

Passing var args to another var args...


I have a function that implements a variable argument list and I would like to create an envelope function that would call it...

So on the one hand, I have:

int OriginalFunction(int parm1, int parm2, char *format, ...)
{
  va_list ap;

  va_start (ap, format);
  if (parm1 == 1)
    DoVaFunc1 (parm2, format, ap);
  else
    DoVaFunc2 (parm2, format, ap);
  va_end (ap);

  return (1);
}

On the other hand, I would like to create a function such as:

int NewFunction (int parm1, int parm2, int parm3, char *format, ...)
{
  int ret = 0;
  if (parm3 == OK)
    ret = OriginalFunction (parm1, parm2, format, ...??...);
  return (ret);
}

So what do I need in the "...???..." section? Is this possible without changing the OriginalFunction?

-- Bubba
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You have two choices:

1. If you can recognise how many parameters there are without calling the function itself, count them and use assembler to push them.

2. The may be a 'v' version. 'vsprintf' is a good example.

Paul

Avatar of bganoush
bganoush

ASKER


jkr: Why can't I remember the small details....

Thanks.

-- Bubba