joemooney
joemooney

Reputation: 1507

Discard existing printf statements and enable newly added printf statements

I have many existing printf statements that I want to disable via:

#define printf(...) {};

But I want to define a new myprintf statement that will still use the stdio printf. How do I do this?

Upvotes: 1

Views: 145

Answers (1)

NPE
NPE

Reputation: 500673

Use:

#define myprintf (printf)

The parentheses will disable macro expansion.

#include <stdio.h>

#define printf(...) do {} while(0)
#define myprintf (printf)

int main() {
  printf("printf\n");
  myprintf("myprintf\n");
}

(Not that I would recommend #defining printf away in the first place...)

For an explanation of why I've used do {} while(0) instead of {}, see Proper C preprocessor macro no-op

Upvotes: 4

Related Questions