Eclipse: comment entire code without it getting cut short by another comment

52 Views Asked by At

Say I have the following code (in C++, but that's probably not important to the question):

int main() {
    ....random code....
    /*This is a comment*/
    ....random code....
    return 0;
}

In eclipse, when I want to comment out the entire code by putting /* and */ before and after the code, the comment is cut short by the */ at the end of the "This is a comment" on line 3, so the rest of the code is left uncommented.

/*    //<--overall comment starts here
int main() {
    ....random code....
    /*This is a comment*/    //<--overall comment ends here
    ....random code....
    return 0;
}
*/  //<--overall comment SHOULD end here

Anyone know a way of getting around this problem, or do I just have to deal with it or use // comments...?

1

There are 1 best solutions below

1
vsoftco On BEST ANSWER

There's no way of having nested comments in C++. One solution (especially if you don't want to change lots of /* */ to //) is to use the pre-processor, you can do something like

#ifdef SOME_RANDOM_SYMBOL

code that you want to comment here

#endif

Just make sure that SOME_RANDOM_SYMBOL is not somehow defined in your code.

As mentioned by @Caleb in the comment, you can also do

#if 0

code that you want to comment here

#endif

but using a symbol allows you to search for it.