Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's an excellent reason <em>not</em> to do this. The following program prints "This will appear".</p> <pre><code>#include &lt;iostream&gt; int main() { std::cout &lt;&lt; "This " // A comment ... \ &lt;&lt; "will appear" // Another comment ... \ &lt;&lt; ", but this won't" &lt;&lt; std::endl; } </code></pre> <p>Why? Because the first <code>\</code> is followed by a blank, and so it's just part of the comment, <em>not</em> a line-splicing character. The program's behavior can quietly and significantly change due to invisible trailing white space.</p> <p>An even better reason not to do this: g++ gets it wrong, even with <code>-pedantic</code>. When I compile this program using g++ the output is just "This"; the trailing white space after the first <code>\</code> is ignored. In my opinion this is how it <em>should</em> work, but it's not what the language standard says. (Line splicing happens in translation phase 2. I suppose one might argue that the trailing blanks could be deleted in phase 1, but I'm not convinced that that's a valid argument -- and I don't know whether the gcc authors have actually made that argument.) In any case, g++ 4.5.2 and Sun CC version 5.5 disagree with each other.</p> <p>If you want multi-line comments, either use <code>/* ... */</code>, or insert a <code>//</code> at the beginning of each line. I prefer the latter, because it's much easier to tell that a given line is part of the comment. (Actually it's multiple single-line comments.) Any decent editor should let you do this without typing <code>//</code> N times for N lines. Or, if you're commenting out a block of code, use <code>#if 0 ... #endif</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload