Joined April 2013
·

Yoann Ricordel

Paris
·
·

Posted to The //* /*/ //*/ comment toggle trick over 1 year ago

Nice trick, thank you for sharing ! One little reserve: at least in C, this fails if the code to toggle contains comments itself:

//*
spawn_unicorns();
/*/
slay_the_unicorns(); /* FIXME: This function kills unicorns ! */
launch_missile();
//*/

In this code, you won't kill unicorns, but you will always launch a missile, which is not what was intented.
It only works in C/C++, but I tend to prefer:

#if 1
spawn_unicorns();
#else
slay_the_unicorns(); /* FIXME: please don't to that. */
launch_missile();
#endif

You just have to change "1" to "0" to toggle between nice and evil code, and it has no restriction regarding embedded comments.

That said, I'll remember your solution for Java, Javascript and others.

Achievements
74 Karma
0 Total ProTip Views
Interests & Skills