• C

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
bganoushAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jkrCommented:
You'd use

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PaulCaswellCommented:
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

0
bganoushAuthor Commented:

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

Thanks.

-- Bubba
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.