Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there a purpose for using a macro that does nothing over an empty macro in c++?

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading