[comp.os.msdos.programmer] General 'C' Preprocessor Question

jmbj@grebyn.com (Jim Bittman) (02/26/91)

Is it possible to use the preprocessor to handle a variable number
of arguments?  Let's say that I want to redefine "printf" to "sprintf".
Is this possible?
  #define printf(a) sprintf(mychbuf,a)
This works just fine if there are no arguments, such as:
  printf("Hello World\n");
This correctly processes to:
  sprintf(mychbuf,"Hello World\n");

I have checked the literature, but nothing seems to touch on this
subject.  Please post or e-mail any responses, I read this group
religously, and really like it!

Thank you.
Jim Bittman, jmbj@grebyn.com

kaufman@delta.eecs.nwu.edu (Michael L. Kaufman) (02/27/91)

In <1991Feb26.082837.5618@grebyn.com> jmbj@grebyn.com (Jim Bittman) writes:
>  #define printf(a) sprintf(mychbuf,a)

How about #define printf(  sprintf(mychbuf

This will not work for most cases, but it will work for you example.

Michael


-- 
Michael Kaufman | I've seen things you people wouldn't believe. Attack ships on
 kaufman        | fire off the shoulder of Orion. I watched C-beams glitter in
  @eecs.nwu.edu | the dark near the Tannhauser gate. All those moments will be
                | lost in time - like tears in rain. Time to die.     Roy Batty