VS2015下,C语言
auto int cnt = 1;
会报错:error C3530: “auto”不能与任何其他类型说明符组合
这是因为:
Before Visual C++ 2010, the keyword declares a variable in the automatic storage class; that is, a variable that has a local lifetime. Starting with Visual C++ 2010, the keyword deduces the type of a variable from the declaration’s initialization expression.
VS2010以前auto是指变量的存储类型,其它三种是:静态类型变量static、寄存器类型变量register和外部类型变量extern。
VS2010后auto语义发生变化,采用了C++语法,是类型推导之意。
如果想使用VS2010之前的auto设定,具体解决方法:
https://docs.microsoft.com/en-us/cpp/build/reference/zc-auto-deduce-variable-type?view=vs-2019
简而言之:
项目属性-C/C+±其他选项 增加/Zc:auto-
即可。
(VS2015测试/Zc:auto
不行,必须是/Zc:auto-
才可以。)