【发布时间】:2012-08-18 19:11:50
【问题描述】:
C++ Primer 说:
我们在程序中定义的标识符可能不包含 2 个连续的 下划线,标识符也不能以下划线开头 立即由一个大写字母。此外,标识符被罚款 函数外不能以下划线开头
一切都很好,但是
int _c = 55; // outside function starts with _
int main () {
int _A = 12; // _ followed by uppercase letter
cout << _A << endl;
int __b__ =33; // 2 consecutive __
cout << __b__ << endl;
cout << _c << endl;
}
上面的代码编译得非常好在mac上,g++ 4.7.1,使用以下标志
g++ -pedantic -Wall -Werror -std=c++11 -O3 -funroll-loops -fprefetch-loop-arrays
请问我错过了什么?
【问题讨论】:
-
当你打破“规则”时,并不保证它不会起作用。它可能会也可能不会。
-
不是所有不正确的东西都必须编译失败。就像不是你可以用英语形成的每一个句子都必须自动有意义。
标签: c++ identifier