_(单下划线)是有效的C ++变量名吗?

_(单下划线)是有效的C ++变量名吗?

问题描述:

使用gcc 4.7.2编译对我来说还不错:

With gcc 4.7.2 this compiles just fine for me:

int main()
{
  int _ = 1;
  return 0;
}

我可以期望它总体上编译吗?我已阅读有关下划线作为前缀的答案.但是,如果下划线不加任何前缀怎么办?

Can I expect this to compile in general? I've read the answers about underscores as prefixes. But what if the underscore isn't prefixing anything?

是,来自C ++编程语言,第4版:

Yes, from The C++ Programming Language, 4th Edition:

名称(标识符)由字母和数字序列组成.这 第一个字符必须是字母.下划线字符_是 被认为是一封信.

A name (identifier) consists of a sequence of letters and digits. The first character must be a letter. The underscore character, _, is considered a letter.