Refactoring: Guard Macro Body

You have a C/C++ macro that needs to perform several statements or contains conditional statements.

Wrap the statements in a do { } while (0) construct to ensure that the statements are executed in the proper order and that the use of the macro doesn’t interfere with other control structures in the program.

Read the rest of this entry »