Meaning of character literals containing trigraphs for non-representable characters

In a C compiler that uses ASCII as its character set, the value of a character literal '??<'will be equivalent to the value '{', i.e. 0x7B. What would be the meaning of this literal in a compiler whose character set does not have a character {?

Outside of the string literal, the compiler can conclude that it ??<should have the same meaning as the open brace character, which matters even if the compiler character set does not have an open anchor character. In fact, the whole purpose of trigraphs is to allow the use of sequences of representable characters instead of characters that are not represented. The specification requires trigraphs to even be processed in string literals, but that puzzled me. If the compiler character set contains a character {, the compiler may allow to '{'be represented as '??<', but the character set includes {. I see no reason why a programmer would not just use this. However, if the character set does not include{, which, apparently, is the only reason for using trigraphs in the first place, what represented character expected the compiler to replace ??<with?

+4
source share
2 answers

When it comes to environmental considerations, especially files, the C standard intentionally gets pretty vague. The following guarantees are made about trigraphs and the coding of their respective characters:

C11 (n1570) 5.1.1.2 p1 ("Translation phases") [emph. my]

  • , , ( ), . .

, . , . , , .

, ( , , , ). , . . 7.21.2 p2:

[...] , , , , : ; ; - . [...]

. 7.4 p3:

" " , , ; " " , , . *) .

*) , US ASCII, , 0x20 () 0x7E (); , 0 (NUL) 0x1F (US) 0x7F (DEL).

, . 7.21.2 p3:

, . , , , , . , , , .

,

printf("int main(void) ??< ??>\n");     // (1) 
printf("int main(void) ?\?< ?\?>\n");   // (2)

, . , isprint('??<') .. ( (1)) isprint('<') .. ( (2)), , C89 :

, -, - , C; , C . , backspace, , .

'??<' .. , , , '??<' .


: C89 .

+1

, {character?

() . { ( 5.2.1/3 C99, [lex.charset]/1 ++ 11). (, ) ( 5.2.1/3 C99, [ lex.charset]/3 ++ 11).

@Mankarse, , ( , ), , , , .

+5

All Articles