$在变量名称? [英] $ in variable name?

查看:136
本文介绍了$在变量名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我偶然发现了一些(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 '_'.

这篇关于$在变量名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆