This page looks best with JavaScript enabled

Comment toggle in C

 ·  🩳 Size XS
    🏷️
  • #c

I’ve just discovered something amazing in C (it also works in C++).

Since C comments cannot be nested, you can use /*/ to toggle “comment-mode”: The compiler will parse it as /* + / the first time and / + */ the second time.

1
2
3
4
5
not_a_comment();
/*/
This is a comment.
/*/
not_a_comment();

It is obvious and stupid and amazing.