trigraphs

Escape sequence for ? in c++

落爺英雄遲暮 提交于 2021-02-07 04:46:32
问题 I was looking at the escape sequences for characters in strings in c++ and I noticed there is an escape sequence for a question mark. Can someone tell me why this is? It just seems a little odd and I can't figure out what ? does in a string. Thanks. 回答1: It's to keep a question mark from getting misinterpreted as part of a trigraph. For example, in "What??!" The "??! would be interpreted as the | character. So, you have to escape the question marks as follows: "What\?\?!" Example complements

Digraph and trigraph can't work together?

拜拜、爱过 提交于 2020-08-25 07:05:02
问题 I'm learning digraph and trigraph, and here is the code which I cannot understand. (Yes, I admit that it's extremely ugly.) This code can compile: #define _(s) s%:%:s main(_(_)) <% __; %>t This code can compile, too: #define _(s) s??=??=s main(_(_)) <% __; %> However, neither of the following two pieces of code can compile: #define _(s) s%:??=s main(_(_)) <% __; %> And #define _(s) s??=%:s main(_(_)) <% __; %> This does confuse me: Since the first two pieces of code can compile, I suppose the

What is the meaning of these strange question marks?

那年仲夏 提交于 2020-07-29 02:40:05
问题 I came across some weird-looking code. It doesn't even look like C, yet to my surprise it compiles and runs on my C compiler. Is this some non-standard extension to the C language and if so, what is the reason for it? ??=include <stdio.h> int main() ??< const char arr[] = ??< 0xF0 ??! 0x0F, ??-0x00, 0xAA ??' 0x55 ??>; for(int i=0; i<sizeof(arr)/sizeof(*arr); i++) ??< printf("%X??/n", (unsigned char)arr??(i??)); ??> return 0; ??> Output: FF FF FF 回答1: The code is fully standard compliant to

What is the meaning of these strange question marks?

柔情痞子 提交于 2020-07-29 02:38:26
问题 I came across some weird-looking code. It doesn't even look like C, yet to my surprise it compiles and runs on my C compiler. Is this some non-standard extension to the C language and if so, what is the reason for it? ??=include <stdio.h> int main() ??< const char arr[] = ??< 0xF0 ??! 0x0F, ??-0x00, 0xAA ??' 0x55 ??>; for(int i=0; i<sizeof(arr)/sizeof(*arr); i++) ??< printf("%X??/n", (unsigned char)arr??(i??)); ??> return 0; ??> Output: FF FF FF 回答1: The code is fully standard compliant to

What does the C ??!??! operator do?

…衆ロ難τιáo~ 提交于 2019-12-17 04:36:11
问题 I saw a line of C that looked like this: !ErrorHasOccured() ??!??! HandleError(); It compiled correctly and seems to run ok. It seems like it's checking if an error has occurred, and if it has, it handles it. But I'm not really sure what it's actually doing or how it's doing it. It does look like the programmer is trying express their feelings about errors. I have never seen the ??!??! before in any programming language, and I can't find documentation for it anywhere. (Google doesn't help

Purpose of Trigraph sequences in C++?

只谈情不闲聊 提交于 2019-12-17 04:14:44
问题 According to C++'03 Standard 2.3/1: Before any other processing takes place, each occurrence of one of the following sequences of three characters (“trigraph sequences”) is replaced by the single character indicated in Table 1. ---------------------------------------------------------------------------- | trigraph | replacement | trigraph | replacement | trigraph | replacement | ---------------------------------------------------------------------------- | ??= | # | ??( | [ | ??< | { | | ??/

Meaning of character literals containing trigraphs for non-representable characters

早过忘川 提交于 2019-12-10 16:47:48
问题 On a C compiler which uses ASCII as its character set, the value of the character literal '??<' would be equivalent to that of '{' , i.e. 0x7B. What would be the value of that literal on a compiler whose character set doesn't have a { character? Outside a string literal, a compiler could infer that ??< is supposed to have the same meaning as an open-brace character is defined to have, even if the compiler character set doesn't have an open-brace character. Indeed, the whole purpose of

Unknown meta-character in C/C++ string literal?

这一生的挚爱 提交于 2019-12-08 21:18:36
问题 I created a new project with the following code segment: char* strange = "(Strange??)"; cout << strange << endl; resulting in the following output: (Strange] Thus translating '??)' -> ']' Debugging it shows that my char* string literal is actually that value and it's not a stream translation. This is obviously not a meta-character sequence I've ever seen. Some sort of Unicode or wide char sequence perhaps? I don't think so however... I've tried disabling all related project settings to no

Are trigraphs still valid C++?

时光毁灭记忆、已成空白 提交于 2019-12-08 17:09:55
问题 We all know about the historical curiosity that is digraphs and trigraphs, but with all the changes made to C++ in recent years I'm curious: are they valid C++14? How about C++17? 回答1: Trigraphs are currently valid, but won't be for long! Trigraphs were proposed for deprecation in C++0x, which was released as C++11. This was opposed by IBM, speaking on behalf of itself and other users of C++, and as a result trigraphs were retained in C++0x. Trigraphs were then proposed again for removal (not

C++1z why not remove digraphs along with trigraphs?

≯℡__Kan透↙ 提交于 2019-11-30 01:04:43
问题 C++1z will remove trigraphs. IBM heavily opposed this (here and here) so there seem to be arguments for both sides of removal/non removal. But since the decision was made to remove trigraphs, why leave digraphs? I don't see any reasons for keeping digraphs beyond the reasons to keep trigraphs (which apparently didn't weight enough to keep them). 回答1: Trigraphs are more problematic to the unaware user than digraphs. This is because they are replaced within string literals and comments. Here