#### Archived

This topic is now archived and is closed to further replies.

# C++ needs the super-comment

This topic is 5037 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

why, oh why, do we not have something like : //* <- this is a super-comment style /* normal c comment */ code /* c comment */ code /* c comment */ code *// so all the above is invisible so we can Super-Comment lots of code? As things stand, then we have to put lots of little annoying comments into code like above, where we just want to hide the whole thing! Just a rant from //* me *//.

##### Share on other sites
/*// normal C++ commentcode// C++ commentcode// C++ commentcode*/

Anyway, what you really want is not "super-comments", but nested comments. Which could be interesting.

##### Share on other sites
#if 0/* normal c comment */code/* c comment */code/* c comment */code#endif

Like that?

##### Share on other sites
Chozo, thank you! That is awesome. I''m going to use that a lot for development. Only wish I''d thought of it!

##### Share on other sites
quote:
Original post by squirrel_of_death
Chozo, thank you! That is awesome. I''m going to use that a lot for development. Only wish I''d thought of it!

Please don''t. It''s ugly as hell and confusing for anyone maintaining the code (#if 0 is easy to miss and the ide won''t provide any syntax colouring for it).

If you want to remove a block of code from execution, delete it! You can always get it back using your version control system (and if you''re not using one now''s the time to start). free source control for windows or for *nix

##### Share on other sites
The editor I use (Kate) has two little functions built in that will comment and uncomment highlighted text. If the text has some /*...*/ comments it''ll put // before each line. (It also works with non C++ language comments.) Quite handy.

##### Share on other sites
I usually just encase blocks of code in /* */... Or did I miss the point somewhere along the line of this thread?

##### Share on other sites
hey ChaosEngine, that''s why I sneaked the word development in there! read : hacking, you know, when you are tearing the code from file to file in huge chuncks. The gestational experimental stuff you dare not let others see. In hope they think of you as some super-coder.

And RuneLancer, yes, the point is, if you import a huge section of code from someone elses code ( or even your own ), and let''s say it''s full of C style comments. Then let''s say you want the whole lot commented out, just so you can compare it directly with your own. Or browse it, whatever. The problem is.. one /* at the top, and */ at the bottom will not work, as all those little c comments cancel you out. And the motivation for this thread was me getting sick of putting all those little comments, when one is all you are looking for. So enter the Super-Comment!! Yay for the SC. Provided by your friendly pre-compiler!!!

##### Share on other sites
Get a better IDE. Any IDE worth its salt can comment out a region of text.

##### Share on other sites
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?

##### Share on other sites
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.

##### Share on other sites
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]

##### Share on other sites
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]

##### Share on other sites
I do exaclty what Red Ghost does. Very useful for debugging.

##### Share on other sites
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.

##### Share on other sites
You can nest #if 0, and a good editor will highlight it. Problem solved.

##### Share on other sites
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.

##### Share on other sites
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

##### Share on other sites
Thanks simba, I''m going to do just that.

##### Share on other sites
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".