gpt4 book ai didi

c++ - cpp文件中的C++变量能否定义为特殊符号β

转载 作者:搜寻专家 更新时间:2023-10-30 23:51:54 25 4
gpt4 key购买 nike

我们可以在 c++/c 中使用特殊字符定义变量吗,例如;
双ε,μ,β,ϰ;

如果是,如何实现?

最佳答案

根据CPP标准工作草案(N4713),

5.10 Identifiers [lex.name]
...
An identifier is an arbitrarily long sequence of letters and digits. Each universal-character-name in an identifier shall designate a character whose encoding in ISO 10646 falls into one of the ranges specified in Table 2. The initial element shall not be a universal-character-name designating a character whose encoding falls into one of the ranges specified in Table 3.

当我们查看表 3 时:

Table 3 — Ranges of characters disallowed initially (combining characters)

0300-036F 1DC0-1DFF 20D0-20FF FE20-FE2F

您提到的符号是希腊字母表,范围从 U+0370U+03FF,扩展的希腊字母集范围从 U+1F0xU+1FFx 根据 wikipedia .这两个范围都可以作为标识符的初始元素。

请注意,并非所有编译器都对此提供支持。

带有 -std=c++17 选项的 GCC 8.2 编译失败。
但是,带有 -std=c++17 选项的 Clang 7.0 可以编译。

Live Demo for both GCC and Clang

关于c++ - cpp文件中的C++变量能否定义为特殊符号β,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52586368/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com