Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Danger in using nested comments for quickly (de)activating code blocks in C++

Tags:

c++

comments

I'm currently using nested comments to quickly activate/deactivate code during testing, the way I'm doing it is like this :

//* First Case, Activated
DoSomething();
/**/

/* Second Case, De-Activated
DoSomethingElse();
/**/

I can activate, deactivate the code blocks by simply adding or deleting a '/'.

The compiler warns me about this, as nested comments are bad, but in reality, is it dangerous to use these comments?

like image 842
3nixios Avatar asked Jan 30 '26 04:01

3nixios


1 Answers

This is how people normally do this:

#if 0
//...
#endif

or

#define TESTWITH

#ifdef TESTWITH
//..
#endif
like image 124
Karoly Horvath Avatar answered Jan 31 '26 17:01

Karoly Horvath