Skip to main content
gamedev.net
🔒 Locked

passing variable argument list to another function

Started by ddungum Feb 15, 2003 at 8:14 AM 3 replies 400+ views
Original Post
ddungum
ddungum
For example, below function accepts variable argument list. ex) void Print(char* format, ...) { va_list vl; va_start(vl, format); vprintf(format, vl); va_end(vl); } And this function too. ex) void PrintError(char* format, ...); When I call PrintError(), I want PrintError() to pass its all arguments to Print() and call it. So I coded like this : ex) void PrintError(char* format, ...) { va_list vl; va_start(vl); Print(format, vl); va_end(vl); } But it doesn''t work. Can somebody tell me how I can pass variable argument list to another function?
niyaw
niyaw
of course you can.

void Print(const char *format, va_list vl) {
vprintf(format, vl);
}

since you aren''t changing format string, indicate so with const.
ddungum
ddungum
I think "niyaw"''s suggestion is right.
But instead, I can''t use Print() with not-va_list parameters any more.
ex) Print("%d", i); //compile error
ex) Print("%d", valist); //ok

Thank you all guys.
Dave Hunt
Dave Hunt
Create an overloaded version, or create a separate function for that and call it something else.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.