[c++] Commenting tricks

When tracking down a compilation problem or even while refactoring code; I find it extremely useful to selectively disable blocks of code. Now I could just wrap the offending section in a ‘#if 0’ and change the 0 to a 1 as needed. Unfortunately not many IDE’s colour these sections correctly, and those that do sometimes get it wrong. Instead I prefer the good old block comment method:

some code
/*
commented code
// */
more code 

Notice how the line with the end of the block comment ‘*/’ has been preceded with a line comment ‘//’? This way you can comment out the start of the block comment with a single slash and not get an error from the unmatched end:

some code
//*
no longer commented code
// */
more code

I realise this is a fairly obvious “trick”, but I haven’t seen it mentioned anywhere else.