简体   繁体   中英

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

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...?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM