Learning c and reading through a project, I found this.
#define EMPTY_MACRO do {} while (0)
...
#if ASSERTS_ENABLED
#define ASSERTCORE(expr) assert(expr)
#else
#define ASSERTCORE(expr) EMPTY_MACRO
#endif
What is the purpose of EMPTY_MACRO
? Is it unnecessary or is there a reason for it?
CodePudding user response:
It's there so
ASSERTCORE(expr);
behaves the same with or without ASSERTS_ENABLED. A plain #define ASSERTCORE(expr)
would leave behind a lone ;
and that would behave differently in some cases.