开发者

Is it safe using `$` as an identifier in C/C++?

Is it safe to use $ character as part of identifier 开发者_运维技巧in C/C++? Like this,

int $a = 10;
struct $b;
class $c;

void $d();


No; it is a non-standard extension in some compilers.


No. The C standard only guarantees the use of uppercase and lowercase English letters, digits, _, and Unicode codepoints specified using \u (hex-quad) or \U (hex-quad) (hex-quad) (with a few exceptions). Specific compilers may allow other characters as an extension; however this is highly nonportable. (ISO/IEC 9899:1999 (E) 6.4.2.1, 6.4.3) Further note that the Unicode codepoint method is basically useless in identifiers, even though it is, strictly speaking, permitted (in C99), as it still shows up as a literal \uXXXX in your editor.


This is not standard and only Microsoft Visual Studio (that I know of) even allows the '$' character in identifiers.

So if you ever want your code to be portable (or readable to others), I'd say no.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜