Neat commenting trick i just discovered.

Started by
19 comments, last by Ezbez 17 years, 6 months ago
If you have commented out segments of code you want to toggle on and off you can do this. Start of with the regular "/*" but end your the section with "//*/" Now if you want to toggle change "/* to "//*"

//*
Some code 
more code
even more code
//*/


/*
Some code 
more code
even more code
//*/
Looks like it doesnt work in the forums source tags.
Advertisement
Neat

i do:

#define DEUBG_1 1
#define DEBUG_2 0

#if DEBUG_1

...
...

#elif DEBUG_2

...
...

#endif


most development editors have mass commenting in and out for selections, VSC++, emacs.

Quote:Original post by iminyourbrain
most development editors have mass commenting in and out for selections, VSC++, emacs.


Yeah I know that. Though this does have a certain convenience to it. With those you have to highlight the entire section of text first. With this each segment of comment is controlled with one key stoke an the that control is placed right at the start of the code segment. And you don't have to hunt for the close comment. Also When the code is toggled on it still marks that code as something you may want to turn off later if you forgotten about it.
If you want to toggle between two pieces of code you can even use:
/*code A/*/code B  //active//*///*code A  //active/*/code B//*/

[COOL]
___________________________Buggrit, millennium hand and shrimp!
Quote:Original post by samv
If you want to toggle between two pieces of code you can even use:
/*code A/*/code B  //active//*///*code A  //active/*/code B//*/

[COOL]
Oh, very nice. I'm sure ill make use of this.

That just seems like a mistake waiting to happen.

CM
Instead of using comment, I usually do sth like this:


#if 0 // toggle to switch
// disabled code
#else
// enabled code
#endif

visit my website at www.kalmiya.com
The last line should be:
// */
to avoid compiler warnings, iirc.
(Note the space)
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms
this is sick
[size="2"]I like the Walrus best.
I concur.
In case you were wondering what to put in your next christian game; don't ask me, because I'm an atheist, an infidel, and all in all an antitheist. If that doesn't bother you, visit my site that has all kinds of small utilities and widgets.

This topic is closed to new replies.

Advertisement