This should be a common problem and possibly similar to some question here but i am looking foe the best way to comment out multiple lines (rather methods ) in C++ which have comments within them .I did check out some posts on SO but couldnt get the full details on using something like if #0 .
I did check out this post Nested comments in Visual C++? but I am not on the Windows platform.
A nested comment is a comment inside another comment. In Java you can't nest a multiline comment into another multiline comment, however you can nest a single line comment into a multiline comment (but does this make sense?) /* This is a comment // this is a nested comment This is another comment */
In C, multi-line comments, /* and */, do not nest. Some guides go so far as to recommend that code sections must never be commented and that if code is to be temporarily disabled one could resort to using an #if 0 directive. See #if 0 to block out code sections.
When someone comments on a previous comment, a “nest” is created. The first comment shows normally, but then the replies to the comment are categorized directly underneath the original comment.
Nested comments are usually a sign that you are using comments wrong. The most common example is commented-out code that contains comments itself, and the fix is to remove the code instead of commenting it out.
You are almost correct; essentially it is being suggested to "if-def" the section of code out. What you want to do is use the precompiler directive #if
to block the code for you. Ex below shows that I want to ignore everything between the if and endif.
#if 0
/* Giant comment
it doesn't matter what I put here */
// it will be ignored forever.
#endif
To answer your question in general though; there is not a way to have compound comments, i.e.
/*
/* */ <--- this closes the first /*
*/ <--- this dangles.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With