C++ needs the super-comment

Started by
18 comments, last by squirrel_of_death 19 years, 11 months ago
And then what happens if you need to super comment a super comment...

You would have the same problem as with the /*...*/ style comments. A better sollution for the problem would be if you actually could nest the comments, so that each /* has a corresponding */, just like brackets or parenthesis. If there''s no ending */ it would comment the whole file.
Advertisement
Is it just for commenting / uncommenting quickly big blocks of code ?
There is a simple solution : instead of */ at the end of your code block, use /**/.
Thus the simple add of /* at the beginning of a code block will comment everything, and the simple removal of the starting /* will uncomment everything.
Example:

void testing (char* pText)
{
first_action();
second_action();
third_action();/**/
}

void commented_testing (char* pText)
{
first_action();
/*second_action();
third_action();/**/
}

Ghostly yours,
Red.

[EDIT: source tags don't interpret correctly that simple trick. Removed them.]

[edited by - Red Ghost on May 7, 2004 2:42:18 AM]
Ghostly yours,Red.
I see why you're wanting to comment out a lot of code but why are you commenting out so much?
You should be working on specialised functions and classes in their own projects then after that is all perfect you add them.
If you keep blocks of code small, specialised and tested like you should then you should not need to comment out such an extreme amount of code.

What you could do however is create your own program that will remove the comments from the file, compile it, then restore the super commented code.

[edited by - auLucifer on May 7, 2004 2:55:42 AM]
I do exaclty what Red Ghost does. Very useful for debugging.
Latest project: Sideways Racing on the iPad
quote:Original post by Red Ghost
Is it just for commenting / uncommenting quickly big blocks of code ?
There is a simple solution : instead of */ at the end of your code block, use /**/.
Thus the simple add of /* at the beginning of a code block will comment everything, and the simple removal of the starting /* will uncomment everything.
Example:

void testing (char* pText)
{
first_action();
second_action();
third_action();/**/
}

void commented_testing (char* pText)
{
first_action();
/*second_action();
third_action();/**/
}

Ghostly yours,
Red.

[EDIT: source tags don''t interpret correctly that simple trick. Removed them.]

[edited by - Red Ghost on May 7, 2004 2:42:18 AM]


That doesn''t solve the problem the OP has though.

You can nest #if 0, and a good editor will highlight it. Problem solved.
quote:Original post by squirrel_of_death
I''m using MS VC++ 6.0. Looking in my Customize menu->keyboard->macros, I get the CommentOut option. However, that just adds a /* ... */ to whatever you select. Any suggestions?


It''s pretty easy to write your own set of custom macros (look it up in the help). I have a whole set i''ve written for various things.
quote:Original post by squirrel_of_death
I''m using MS VC++ 6.0. Looking in my Customize menu->keyboard->macros, I get the CommentOut option. However, that just adds a /* ... */ to whatever you select. Any suggestions?


In MSVC .NET using the comment shortcut adds a comment with // at the start of each line of text selected (similarly the uncomment removes these without interfering with previously set // comments). If only a small portion of text in one line is selected then it uses the /* */ style comments. Maybe its time to upgrade :D
Thanks simba, I''m going to do just that.
Mathematica apparently supports nested comments. It uses (* and *) for comments instead of /* and */, and nested comments work perfectly fine. For example, the expression "xxx(*abc(*def*)ghi(*klm*)nop*)zzz" gives the expected output of "xxx zzz".

This topic is closed to new replies.

Advertisement