I want to implement a macro named PRINT which gets zero or more parameters, and does the following:
- If it gets zero parameters - do nothing.
- If it gets one or more arguments - act like printf.
I succeed in implementing it as you can see in my code below, but only at the cost of calling to printf with an empty string in the case we get zero arguments.
Is there a way I can handle the zero arguments case without calling to printf (it's not efficient to print something when you just want to do nothing)?
#include <stdio.h>
#define PRINT(...) printf("" __VA_ARGS__);
int main(){
PRINT();
PRINT("print\n");
PRINT("print number: %d\n", 7);
return 0;
}
output:
print
print number: 7