Variable argument lists

A

Anders Andersen

Hi,

I have a question about about the use og va_start, va_arg, va_end, ...

I'm trying to pass a variable argument list from one function to
another, but I can't get it to work. My code looks someting like this:

int func_one(char *arg, ...) {
va_list ap;

va_start(ap, arg);
...
/* call func_two with the same arguments as func_one was called */
func_two(arg, ap);
...
va_end(ap);

}

int func_two(char *arg, ...) {
...
}

Can anybody help me with this? Is it possible at all?

/Anders.
 
J

James Hu

I'm trying to pass a variable argument list from one function to
another, but I can't get it to work. My code looks someting like this:

int func_one(char *arg, ...) {
va_list ap;

va_start(ap, arg);
...
/* call func_two with the same arguments as func_one was called */
func_two(arg, ap);
...
va_end(ap);

}

int func_two(char *arg, ...) {
...
}

Can anybody help me with this? Is it possible at all?

int func_two(char *arg, va_list ap) {
/* ... */
}

func_two does not need to use va_start/va_end.

-- James
 
H

Hallvard B Furuseth

James said:
int func_two(char *arg, va_list ap) {
/* ... */
}

func_two does not need to use va_start/va_end.

Actually, it would be an error for it to use them.
 
G

Gabor Drasny

Anders said:
Hi,

I have a question about about the use og va_start, va_arg, va_end, ...

I'm trying to pass a variable argument list from one function to
another, but I can't get it to work. My code looks someting like this:

int func_one(char *arg, ...) {
va_list ap;

va_start(ap, arg);
...
/* call func_two with the same arguments as func_one was called */
func_two(arg, ap);
...
va_end(ap);

}

int func_two(char *arg, ...) {
...
}

Can anybody help me with this? Is it possible at all?

/Anders.

Yes, but only if you declare func_two as

int func_two(char *arg, va_list ap) {
...
}

You might want to keep the other func_two (with the ...) and
have it call this func_two (with the va_list), but the real
"work" has to be done in the va_list version.

Cheers,

Gabor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,954
Messages
2,570,116
Members
46,704
Latest member
BernadineF

Latest Threads

Top