Jump to content
  • Advertisement
Sign in to follow this  
yacwroy

C: wrapping printf and passing ellipsis

This topic is 3616 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

I'm working with old C code. I'm trying to create a member function that lets me forward: foo.print(char* str, ...) to fprintf(foo.file, str, ...) if foo.test is false. something like:
struct foo
{
  FILE* file;
  int test;
  void print(char*, ...);
}

void foo::print(char* str, ...)
{
  if(!test)
    fprintf(file, str, ...);
}


Unfortunately it seems you can't pass ellipses. I thought of doing it with a macro but I can't get it to work: e.g. (these obviously don't work) #define MY_PRINTF( if(myfoo.test) fprintf(myfoo #define MY_PRINTF(...) if(myfoo.test) fprintf(myfoo, ...) Is there some internal printf() function I can pass foo::print()'s va_args to that's standard? Can anyone think of another way I forward foo::print() to fprintf()? Thanks for all assistance. [Edited by - yacwroy on November 26, 2008 6:07:09 AM]

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by yacwroy
Is there some internal printf() function I can pass foo::print()'s va_args to that's standard?
Sure. Google 'vsprintf'.

Also, be careful. C doesn't support member functions.

Share this post


Link to post
Share on other sites
You probably tried to be funny with the C-- in the topic title, but there actually is a language called C--, which is a low level intermediate language that is intended for internal use in compilers. I couldn't find a link quickly but it's out there. The topic causes confusion.

So now you tricked me to check out the topic and wasted my time :( I thought there was going to be compilers and other interesting related stuff.

-riku
edit: http://www.cminusminus.org/ found the url

Share this post


Link to post
Share on other sites
Quote:
Original post by yacwroy
I'm working with old C code.

I'm trying to create a member function that lets me forward:
foo.print(char* str, ...)
to
fprintf(foo.file, str, ...)
if foo.test is false.


It's perfectly possible to use fprintf() to print a plain string; so why not develop a proper C++ interface to build up a string and then forward it all in one go? For that matter, if you can write member functions, why can't you just use C++ I/O? What exactly does your "working with" old C code entail? Are you calling some function that returns a FILE* to you or something?

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!