Horje

POSSIBLE pitfall due to trigraphs - Comments - C
Learn
C - Comments - Possible pitfall due to trigraphs
Possible pitfall due to trigraphs

While 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 now will get interpreted into \. This is because the ??/ forms a trigraph (opens new window).

The ??/ trigraph is actually a longhand notation for \, which is the line continuation symbol. This means that the compiler thinks the next line is a continuation of the current line, that is, a continuation of the comment, which may not be what is intended.

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;

Syntax

  • /*...*/
  • //... (C99 and later only)
Read Article
https://develop.horje.com/learn/1434/reference