Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Variable Argument List

Posted on 1999-06-23
2
Medium Priority
?
298 Views
Last Modified: 2010-04-15
Hi experts,

I want to have a function with variable arguments.  my question whether the variable arguments will be stored automatically in va_list (or) I have to store it.  for example.

function declaration:

int calculate(int arg1, int arg2, va_list v1);

actual call:
------------
calculate(int arg1, int arg2, int arg3, int arg4);

the question is whether if I call calculate like above, whether the arguments arg3 & arg4 will be stored automatically in valist (or) I have to store it by myself before calling it.

Actually I don't to store the valist myself.  your sugesstions are welcomed.

Best Regards,
P R A T H A P
0
Comment
Question by:chowdry
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 14

Accepted Solution

by:
AlexVirochovsky earned 200 total points
ID: 1262921
It is very simple: Translator make stack and save in it
all needed var's. You don't need store anything(but must
make more big stack!).
Good luck, Alex
0
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 1262922
I think, i must add some little example:
/* va_arg example */

#include <stdio.h>
#include <stdarg.h>

/* calculate sum of a 0 terminated list */
void sum(char *msg, ...)
{
   int total = 0;
   va_list ap;
   int arg;
   va_start(ap, msg);
   while ((arg = va_arg(ap,int)) != 0) {
      total += arg;
   }
   printf(msg, total);
   va_end(ap);
}

int main(void) {
   sum("The total of 1+2+3+4 is %d\n", 1,2,3,4,0);
   return 0;
}
Can be , it helps.
Alex



0

Featured Post

Technology Partners: 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…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

722 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