Reputation: 1507
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
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