Jump to content
  • Advertisement
Sign in to follow this  
Daichi

C++: Wrapping Ellipses arguments into another function. (printf)

This topic is 4896 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm using VC++6, I haven't delt much with the Ellipses (...) argument much before, So I'm very confused. I'm trying to do something similar to this concept.
int myprintf(const char *format , ...) {
  return printf(format, ...); // <-- how to deal with the multiple arguments
}

I don't need to do anything with the arguments other then pass it to my next function. -Daichi

Share this post


Link to post
Share on other sites
Advertisement
You must "use" those arguments in the function that recieves them. Look up the _vsnprintf function or the vsprintf function. They will format your string into a buffer which you can then pass to printf or whatever you like. MSDN should have examples.

Share this post


Link to post
Share on other sites
This is how I do stuff like that:



#include <varargs.h>

void myPrintf(const char* const text, ...)
{
va_list va;
va_start(va, text);
otherPrintf(text, va);
va_end(va);
}

void otherPrintf(const char* const text, va_list& va)
{
char temp[1024];
_vsnprintf(temp, 1024, text, va);
printf(temp);
}



Stupid sample, but you get the point.
Sending multiple arguments is done by using a reference to a va_list.
Sending all the arguments that is defined using the ... operator is not possible (without some serious assembler hacking) to my knowledge.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!