4

I'm working on a proprietary unix-like os (I don't know if that's relevant though) and compiling with g++.

I noticed recently that if I put xml-like tags in my C++ comments I get compiler errors. I don't particularly need to do this, but I thought it was strange and I'd like to know why it's an issue for the compiler. For example:

// <debugoutput>
std::cerr << "I'm debugging!" << std::endl;
// </debugoutput>

would cause massive compiler errors if it were in the middle of my code somewhere. Changing the last comment line </debugoutput> to <debugoutput> makes it compile fine though.

Does anyone know why the compiler would be confused by that line being in a comment? The compiler errors generated when this happens don't seem related at all - they're more like what you'd see if you missed the semi colon on the end of a class, undefined references to well defined classes, etc. I can't paste the output from my dev system, but trust me that it doesn't look related to the issue - its more like the compiler got confused.

Benjamin Lindley
  • 101,917
  • 9
  • 204
  • 274
John Humphreys
  • 37,047
  • 37
  • 155
  • 255
  • Can you please post a minimal example that illustrates the error, and also tell us what error the compiler prints? If it's multiple errors, you don't really have to include them all. Just the first error message should be sufficient. – Rob Kennedy Sep 08 '11 at 19:06
  • Need to see more code. A simple example (like above) works on gcc 4.6.0. – Chad Sep 08 '11 at 19:08
  • I can't seem to replicate it in any simple program - the project this is happening in is a very large project and it's being built with multi-threaded make (which has never been a problem before, but thought it might matter). I know that's not lots to go on, but i was hoping someone might have ran into something similar before. – John Humphreys Sep 08 '11 at 19:14
  • 1
    Even if you can't replicate it in a simple program, the actual error message would still be helpful. – David Brown Sep 08 '11 at 19:32
  • It's a closed system and the compiler dump is all very program specific (class names, undefined references, etc) even if I could provide it, so it wouldn't help unless you could see the program which is definitely not possible unfortunately. Anyway, I'll close it out with the digraph solution - that seems to be the only one with any input. – John Humphreys Sep 09 '11 at 15:19
  • Do you have a backslash at the end of a line? Is the OS really so proprietary that you can't tell us what it is? – Keith Thompson Sep 09 '11 at 18:25

1 Answers1

3

This sounds suspiciously like a digraph related issue, but without the actual error message or a small code sample that exhibits the problem it's hard to tell for sure.

Try changing the whitespacing between the <, / and actual text, as well as try it within a C-style comment to see if that provides additional insight.

For information on C/C++ digraphs and trigraphs see http://en.wikipedia.org/wiki/C_trigraph#C and also Purpose of Trigraph sequences in C++? and Why are there digraphs in C and C++? from SO.

It seems possible that there is some sequence being picked up (for example </ as a digraph and it's throwing off the compiler).

Community
  • 1
  • 1
Mark B
  • 95,107
  • 10
  • 109
  • 188
  • Changing the comment style and spacing does seem to mitigate the problem for some reason. As for the compiler output and code - they're on a closed system and the output doesn't even relate to the changed files - its more about class defs not being found and things like that. If I could post I would, but it would be thousands of lines of compiler errors when this happens, haha. What do you mean by a "diagraph" issue? I'll close it out if you let me know that :) – John Humphreys Sep 09 '11 at 14:51
  • Digraphs won't matter, because whatever digraph you've communicated, it's still commented out. And you can't end a `//` comment with any character except a new line, which isn't a digraph or trigraph. – Puppy Sep 09 '11 at 15:02
  • @DeadMG Not a properly conforming compiler's implementation of digraphs anyway, but if it's a more obscure system, or there's some other step we aren't seeing... – Mark B Sep 09 '11 at 15:06