dollar sign in variable name?(变量名中的美元符号?)
问题描述
我偶然发现了一些这样的 C++ 代码:
I stumbled on some C++ code like this:
int $T$S;
首先,我认为这是某种 PHP 代码或错误粘贴的内容,但它编译并运行良好(在 MSVC 2008 上).
First I thought that it was some sort of PHP code or something wrongly pasted in there but it compiles and runs nicely (on MSVC 2008).
哪些字符对 C++ 中的变量有效?还有其他奇怪的字符可以使用吗?
What kind of characters are valid for variables in C++ and are there any other weird characters you can use?
推荐答案
唯一符合标准的合法字符是字母数字和下划线.该标准确实要求几乎任何事情Unicode 认为字母是可以接受的(但只能作为单个代码点字符).在实践中,实现提供了扩展(即有些确实接受 $)和限制(大多数不接受所有所需的 Unicode 字符).如果你希望你的代码是可移植的,将符号限制为 26 个无重音字母,大写或小写,十位数字和_".
The only legal characters according to the standard are alphanumerics and the underscore. The standard does require that just about anything Unicode considers alphabetic is acceptable (but only as single code-point characters). In practice, implementations offer extensions (i.e. some do accept a $) and restrictions (most don't accept all of the required Unicode characters). If you want your code to be portable, restrict symbols to the 26 unaccented letters, upper or lower case, the ten digits, and the '_'.
这篇关于变量名中的美元符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:变量名中的美元符号?
基础教程推荐
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- CString 到 char* 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
