Toggle Code Blocks with C Comments

Toggle Code Blocks with C Comments

If you find yourself constantly commenting and uncommenting bits of code during development, this tip could come in handy.

Normally, you’d do something like this:

 #define /* #undef */ _FOObool x = true; // = false;

Instead, use C style commenting to your advantage:

 /**/ #define /*/ #undef /**/ _FOObool x = /**/ true /*/ false /**/;

This defines _FOO and sets x to true. Deleting or adding the second slash toggles the comments:

 /** #define /*/ #undef /**/ _FOObool x = /** true /*/ false /**/;

This also works when you have large chunks of code you wish to “toggle” and a preprocessor define would be overkill. Keep in mind this makes code harder to read to someone not familiar with the technique, so let your team know how it works and use it sparingly!

See also  11 Effective Keyword Research Tools and Techniques

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist