Possible pitfall due to trigraphs
suggest changeWhile writing // delimited comments, it is possible to make a typographical error that affects their expected operation. If one types:
int x = 20; // Why did I do this??/
The / at the end was a typo, but in C17 and earlier it is interpreted as \. That is because ??/ is a trigraph.
The ??/ trigraph is a spelling of \, the line-continuation character. The compiler splices the next physical line onto this one before it recognizes comments, so the next line can become part of the comment. Trigraphs were removed in C23.
int foo = 20; // Start at 20 ??/
int bar = 0;
// The following will cause a compilation error (undeclared variable 'bar')
// because 'int bar = 0;' is part of the comment on the preceding line
bar += foo;
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents