_(单下划线)是有效的C ++变量名吗? [英] Is _ (single underscore) a valid C++ variable name?

查看:122
本文介绍了_(单下划线)是有效的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.

这篇关于_(单下划线)是有效的C ++变量名吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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