Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Passing var args to another var args...

Posted on 2004-11-22
3
Medium Priority
?
268 Views
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);
  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
0
Comment
Question by:bganoush
3 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 12645522
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
 
LVL 16

Expert Comment

by:PaulCaswell
ID: 12646405
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
 

Author Comment

by:bganoush
ID: 12646579

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

Thanks.

-- Bubba
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
Suggested Courses

564 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