Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Yes, your expected result is the one required by the C and C++ standards. The backslash simply escapes the newline, i.e. the backslash-newline sequence is deleted.</p> <p>GCC 4.2.1 from my OS X installation gives the expected result, as does Clang. Furthermore, adding a <code>#define</code> to the beginning and testing with</p> <pre><code>#define main(){\ return 0; } main() </code></pre> <p>yields the correct result</p> <pre><code>} {return 0; </code></pre> <p>Perhaps <code>gcc -E</code> does some extra processing after preprocessing and before outputting it. In any case, the line break seen by the rest of the preprocessor seems to be in the right place. So it's a cosmetic bug.</p> <p><strong>UPDATE:</strong> According to the <a href="http://gcc.gnu.org/wiki/FAQ#cpp_continuation_discarded" rel="noreferrer">GCC FAQ</a>, <code>-E</code> (or the default setting of the <code>cpp</code> command) attempts to put output tokens in roughly the same visual location as input tokens. To get "raw" output, specify <code>-P</code> as well. This fixes the observed issues.</p> <p>Probably what happened:</p> <ol> <li>In preserving visual appearance, tokens not separated by spaces are kept together.</li> <li>Line splicing happens before spaces are identified for the above.</li> <li>The <code>{</code> and <code>return</code> tokens are grouped into the same visual block.</li> <li><code>0</code> follows a space and its location on the next line is duly noted.</li> </ol> <p><strong>PLUG:</strong> If this is really important to you, I have implemented <a href="http://code.google.com/p/c-plus" rel="noreferrer">my own preprocessor</a> with correct implementation of both raw-preprocessed and whitespace-preserving "pretty" modes. Following this discussion I <a href="http://code.google.com/p/c-plus/source/detail?r=d462b650c355b606545158f4da7365180b699752" rel="noreferrer">added</a> line splices to the preserved whitespace. It's not really intended as a standalone tool, though. It's a testbed for a compiler framework which happens to be a fully compliant C++11 preprocessor library, which happens to have a miniature command-line driver. (The error messages are on par with GCC, or Clang, sans color, though.)</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. 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.
    1. CO" your expected result is the one required by the C and C++ standards. " -- Not at all -- the standards do not require that implementations output C code, and they say nothing about the format of C code generated by programs that do. "So it's a cosmetic bug." -- It's not a bug at all, because the format of the output of gcc -E is not specified, other than that it will compile correctly.
      singulars
    2. CO@JimBalter The output of phase 4 is well-defined enough to be observable. It consists of spaces, newlines, and preprocessing tokens. The standards don't require it to be observable, but if the preprocessor output is indeed what he's observing, the standard specifies what it should be, and where the newline goes. (There is no textual indication of token boundaries, so the text representation certainly falls short a bit.) I'm sure this is documented, and since GCC is supposed to conform to its own documentation, it might be more serious as a bug. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57714
      singulars
    3. COI've reconsidered this and agree that it's a GCC bug, because running the output of gcc -E through the compiler will give the wrong line number for an error if, say, the `0` in the OP's code is replaced by `x` or something else not allowed at that point. There's a response from Andrew Pinski to your bugzilla report claiming that it's the right output, but he's clearly wrong.
      singulars
 

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