[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Variable Argument List

Posted on 1999-06-23
2
Medium Priority
?
301 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
  • 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

Live webcast with Pinal Dave

Pinal Dave will teach you tricks to help identify the real root cause of database problems rather than red herrings. Attendees will learn scripts that they can use in their environment to immediately figure out their performance Blame Shifters and fix them quickly.

Question has a verified solution.

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

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…
There's never been a better time to become a computer scientist. Employment growth in the field is expected to reach 22% overall by 2020, and if you want to get in on the action, it’s a good idea to think about at least minoring in computer science …
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Suggested Courses

591 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