Answer the question
In order to leave comments, you need to log in
How to make a macro in C with an unlimited number of arguments that can be "disabled"?
I want all debug messages to be included if only one define is done. I have this: DEBUG("program started\n");
and I have this:
#define DEBUG(str) \
#ifdef __DEBUG__ \
printf("DEBUG: " str); \
#endif
and the program should only print "DEBUG: program started" if you add -D__DEBUG__ before the compiler options . But firstly, it doesn’t work, and secondly, it’s done only for 1 argument, but I would have for any number. error: '#' is not followed by a macro parameter
#define DEBUG(...) \
printf("DEBUG: " __VA_ARGS__);
but I need to disable the debugger. For this he did this:#ifdef __DEBUG__
#define DEBUG(...) printf("DEBUG: " __VA_ARGS__);
#endif
but here if you do not define __DEBUG__ then I get an error because DEBUG is undefined. How then, otherwise, can DEBUG be defined so that it doesn't do anything?#ifdef __DEBUG__
#define DEBUG(...) printf("DEBUG: " __VA_ARGS__);
#else
// Что тут писать чтобы объявить DEBUG() который ничего не делает?
#endif
Answer the question
In order to leave comments, you need to log in
#ifdef __DEBUG__
#define DEBUG(...) printf("DEBUG: " __VA_ARGS__);
#else
#define DEBUG(...)
#endif
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question