Passing var args to another var args...

Posted on 2004-11-22
Last Modified: 2010-04-15

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);
    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
Question by:bganoush
    LVL 86

    Accepted Solution

    You'd use

    int NewFunction (int parm1, int parm2, int parm3, char *format, ...)
     va_list args;
     int ret = 0;
     if (parm3 == OK)
       ret = OriginalFunction (parm1, parm2, format, args);
     return (ret);
    LVL 16

    Expert Comment

    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.



    Author Comment


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


    -- Bubba

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
    Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
    The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
    The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now