Files
CPlusPlusThings/site_extras/cpp-idioms-trigraphs-cpp.md
light-city dfe1c933b3 docs: address community issue feedback (#5 #338 #142 #246 #136 #303)
- const README: rewrite the space-saving claim per issue #5 follow-ups
  (constant-expression const vs #define immediates; which const qualify
  as constant expressions)
- const README: fix the class-section diagnosis per issue #338 (overload
  resolution picks the const overload; the restriction only surfaces
  once that overload is removed)
- sizeof README: virtual-inheritance result is compiler-dependent
  (GCC merges vbptr+vfptr -> 16, MSVC keeps them separate -> 32) #246
- static README: new section on internal linkage / access restriction
  with anonymous-namespace comparison #142
- 10-day practice: full problem list table + fixed day links #136
- new design_pattern/singleton/singleton_default.hpp: reusable
  thread-safe CRTP singleton template, compile+concurrency tested #303
2026-10-13 19:23:54 +08:00

51 lines
1.1 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
> 来自 [C++那些事网站](https://light-city.github.io/stories_things/cpp-idioms/trigraphs-cpp/) 的文章,由站点同步脚本导出。
# C++ 三字母词
## C++那些事之删除三字母
C++17 之前,Trigraph 是用 ISO/IEC 646 等小字符代码编写程序的功能,在 C89 中引入。 ISO/IEC 646 缺少 C 中使用的以下字符,因此`??`请使用以下字符进行转义:
| 三字母内容 | 替换的内容 |
| ---------- | ---------- |
| `??=` | `#` |
| `??(` | `[` |
| `??)` | `]` |
| `??<` | `{` |
| `??>` | `}` |
| `??/` | `\` |
| `??!` | `|` |
| `??-` | `~` |
| `??'` | `^` |
`\?`它被转义以防止被三字母表替换。
C++17三字母被删除,`??=`等不再被替换。
## 示例
C++17之前:
```cpp
std::cout << "??=" << std::endl;
std::cout << "??(" << std::endl;
std::cout << "?\?(" << std::endl;
```
输出:
```
#
[
??(
```
C++17及之后:
```
??=
??(
??(
```
现在可能由于Unicode等字符编码已经普遍存在,不再需要三字母组,而gcc等编译器默认禁用三字母组。