• C

Variable Argument List

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,
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.

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

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
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);

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.

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

From novice to tech pro — start learning today.