gpt4 book ai didi

unicode - g++ unicode 变量名

转载 作者:行者123 更新时间:2023-12-03 12:25:41 25 4
gpt4 key购买 nike

我正在尝试在 g++ 中使用 unicode 变量名。

它似乎不起作用。

g++ 是否不支持 unicode 变量名称,...或者是否有一些 unicode 子集(我没有从中进行测试)。

谢谢!

最佳答案

您必须指定 -fextended-identifiers编译时标记,您还必须使用\uXXXX 或\uXXXXXXXX 作为 unicode(至少在 gcc 中它是 unicode)

g++ 中的标识符(变量/类名等)不能是 utf-8/utf-16 或任何编码,
他们必须是:

identifier:
nondigit
identifier nondigit
identifier digit

非数字是
nondigit: one of
universalcharactername
_ a b c d e f g h i j k l m n o p q r s t u v w x y z
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

一个通用字符名称是
universalcharactername:
\UXXXXXXXX
\uXXXX

因此,如果您将源文件保存为 UTF-8,则不能有像例如这样的变量:
int høyde = 10;

它必须写成:
int h\u00F8yde = 10;

(imo会打败整个目的 - 所以坚持a-z)

关于unicode - g++ unicode 变量名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2681778/

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