• Advertisement
Sign in to follow this  

Super comment

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Sometimes in a block of C++ code, I have the /* */ and sometimes I want to comment all of the code so if I put another /* */, it becomes a headache. example
zfunction()
{
/*thing
thing
thing
if(ypasdafsdf)
{  thing
  /*thing
   thing*/
}
thing
thing
thing*/
}


Is there a solution to this?

Share this post


Link to post
Share on other sites
Advertisement
Or use // comments. In a good IDE or editor, you should be able to select the text you want to comment, and then press some key combination to //-ify it.

Personally, I never understood why they made /* */ not nestable. I can understand that in the 70's in the C programming language they might have done it to make the parser of the code a bit more efficient. But I don't understand that other curly brace language, like Java, followed this and still don't allow nesting /* */ comments...

Share this post


Link to post
Share on other sites

zfunction()
{
/*thing
thing
thing
if(ypasdafsdf)
{ thing
/*thing
thing*//*
}
thing
thing
thing*/
}


Closest I could get to a solution. I personally only use /**/ for header comments and use // to comment out code (it can be a PITA to do manually, but it's better than dealing with nested /**/ comments).

I hate GD.net's forum software, could someone tell my how to post code in code tags? I tried but the above is what happens.

Share this post


Link to post
Share on other sites
Quote:
Original post by Lode
Or use // comments. In a good IDE or editor, you should be able to select the text you want to comment, and then press some key combination to //-ify it.

Personally, I never understood why they made /* */ not nestable. I can understand that in the 70's in the C programming language they might have done it to make the parser of the code a bit more efficient. But I don't understand that other curly brace language, like Java, followed this and still don't allow nesting /* */ comments...


It can't be represented with a regular expression that way, so the lexical analyzer becomes more complicated. C# allows nesting I believe, but in a language that operates on design-by-committee, it's really hard to get anything changed.

To the OP, if you're using Visual Studio, highlight everything and hit Ctrl+K C

Share this post


Link to post
Share on other sites
Some C compilers allow comment nesting, although that was non-standard behaviour. I doubt any major compiler still does it, at least by default.

But yeah, if you want to disable code that contains that kind of comments, use #ifdef 0 ... #endif. It also has the additional advantage that it can be nested!

Share this post


Link to post
Share on other sites
Quote:
Original post by cache_hit
Quote:
Original post by Lode
Or use // comments. In a good IDE or editor, you should be able to select the text you want to comment, and then press some key combination to //-ify it.

Personally, I never understood why they made /* */ not nestable. I can understand that in the 70's in the C programming language they might have done it to make the parser of the code a bit more efficient. But I don't understand that other curly brace language, like Java, followed this and still don't allow nesting /* */ comments...


It can't be represented with a regular expression that way, so the lexical analyzer becomes more complicated. C# allows nesting I believe, but in a language that operates on design-by-committee, it's really hard to get anything changed.

To the OP, if you're using Visual Studio, highlight everything and hit Ctrl+K C


#if 0 is good but your Ctrl+K C is nice as well. It works in VC++ 2008 Express.
May I ask how did you learn about the Ctrl+K C?
Is it in the menu?

Share this post


Link to post
Share on other sites
Yes this has pissed me off over the years as well, nested comment blocks would be nice.

Share this post


Link to post
Share on other sites
Quote:
Original post by Firestryke31
I hate GD.net's forum software, could someone tell my how to post code in code tags? I tried but the above is what happens.


Take a look at this sticky thread which has some useful information on source tags.

Share this post


Link to post
Share on other sites
Quote:
Original post by _moagstar_
Quote:
Original post by Firestryke31
I hate GD.net's forum software, could someone tell my how to post code in code tags? I tried but the above is what happens.


Take a look at this sticky thread which has some useful information on source tags.


Plus of course the dreaded FAQs: FAQ on tags.

Share this post


Link to post
Share on other sites
Even if there were nested comments, for code I'd still prefer #if 0 ... #endif because the IDE still treats the contents as code, so you get all the auto-indentation, Intellisense, special features like refactoring, etc. Otherwise it's just a blob of text and a nightmare to do anything with.

Share this post


Link to post
Share on other sites
Quote:
Original post by Zipster
Even if there were nested comments, for code I'd still prefer #if 0 ... #endif because the IDE still treats the contents as code, so you get all the auto-indentation, Intellisense, special features like refactoring, etc. Otherwise it's just a blob of text and a nightmare to do anything with.


Note that there is also the alternative of commenting out sourecode by using "if(false) {}", in case you want to comment out code, but at the same time you want the stuff inside conserve over a longer time without deprecation, or just to escape language standard issues with indendation of preprocessor statements. About indendation, I think the only sanctioned way to do indendation is as follows:

#if xxx
# if yyy
# define foo bar
# endif
#endif


with the #'s always being the first character on the line.


Update:
Quote:
ISO/IEC 9899:TC2, 6.10.2 (C99 TC2)
Apreprocessing directive consists of a sequence of preprocessing tokens that begins with a # preprocessing token that (at the start of translation phase 4) is either the first character in the source file (optionally after white space containing no new-line characters) or that follows white space containing at least one new-line character, and is ended by the next new-line character.


Which is identical in ISO/IEC 14882:2003(E), 16.1 (C++ 2003), so it is sanctioned by the Holy Standards of C99 and C++2003 to write:

int main () {
#if xxx
#if yyy
#define foo bar
#endif
#endif
}


Even if MSVC will bully it away by default.

[Edited by - phresnel on September 14, 2009 5:41:23 AM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement