int main()
{
G_int_val++;
return 0;
}
//error: file-scope declaration of 'G_int_val' specifies 'auto'
//编译OK的程序
int main()
{
auto char ch;
return 0;
}
...全文
6406打赏收藏
C关键字auto的使用方法
工作2年了,从来没用过关键字auto,心血来潮用了一把竟然编译错误(gcc 4.4.6), 求解释,auto不能修饰全局变量吗?看过好几本书都说所有变量默认都是auto类型的。 //编译错误的程序 auto int G_int_val; int main() { G_int_val++; return 0; } //error: file-scope declaration of 'G_int_val' specifies 'auto' //编译OK的程序 int main() { auto c
The auto and register specifiers give the declared objects automatic storage class,and may be used only within functions. Such declarations also serve as definitions and cause storage to be reserved.