是否可以将cpp文件中的C ++变量定义为特殊符号β [英] Can C++ variables in cpp file defined as Special Symbols β
问题描述
我们可以在c ++ / c中使用特殊字符定义变量吗?
doubleε,µ,β,ϰ;
Can we define the variable in c++/ c using special characters such as;
double ε,µ,β,ϰ;
如果是的,如何实现?
推荐答案
根据CPP标准(N4713)的工作草案,
As per the working draft of CPP standard (N4713),
5.10标识符[lex.name]
...
标识符是任意长字母序列和数字。标识符中的每个通用字符名称都应指定一个字符,其字符在ISO 10646中的编码应属于表2中指定的范围之一。初始元素不得是表示编码字符属于其范围的字符的通用字符名称。进入表3中指定的范围之一。
再看表3:
表3 —最初不允许的字符范围(组合字符)
Table 3 — Ranges of characters disallowed initially (combining characters)
0300-036F 1DC0-1DFF 20D0-20FF FE20-FE2F
您提到的符号是希腊字母,范围从 U + 0370
到 U + 03FF
以及扩展的根据 U + 1F0x 到 U + 1FFx
。 wikipedia.org/wiki/List_of_Unicode_characters rel = nofollow noreferrer>维基百科。这两个范围都可以用作标识符的初始元素。
The symbols you have mentioned are the Greek Alphabet which ranges from U+0370
to U+03FF
and the extended Greek set ranges from U+1F0x
to U+1FFx
as per wikipedia. Both these ranges are allowed as the initial element of an identifier.
请注意,并非所有编译器都对此提供支持。
带有 -std = c ++ 17
选项的GCC 8.2无法编译。
但是,Clang 7.0带有 -std = c ++ 17
选项进行编译。
GCC 8.2 with -std=c++17
option fails to compile.
However, Clang 7.0 with -std=c++17
option compiles.
这篇关于是否可以将cpp文件中的C ++变量定义为特殊符号β的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!