在MS的Visual C启用沃拉斯(可变长度数组)++? [英] Enabling VLAs(variable length arrays) in MS Visual C++?
问题描述
如何才能允许使用沃拉斯的,如C99定义,在微软的Visual C ++或这是不可能的变长数组呢?
是的,我知道C ++标准是基于C89和沃拉斯不在C89标准提供,因此不使用C ++的,但MSVC ++应该是一个C语言编译器也可以转换行为使用/ TC编译器参数(编译为C code(/ TC)
)。但这样做似乎没有使沃拉斯和编译过程中失败,并为C ++构建时,同样的错误(编译为C ++ code(/ TP)
)。也许MSVC ++ C编译器是C89仅兼容或者我失去了的东西(/定义一些特殊构造或编译)?
code样品:</ P>
的#include&LT;&stdlib.h中GT;INT主(INT ARGC,字符** argv的)
{
焦炭PC [ARGC + 5]; / *做一些与PC有用的* / 返回EXIT_SUCCESS;
}
编译错误:
错误C2057:预期不断前pression
错误C2466:不能分配常量大小的数组0
错误C2133:'PC':未知大小
块引用>解决方案MSVC不是C99编译器,并且不支持可变长度数组。
在<一个href=\"http://msdn.microsoft.com/en-us/library/02y9a5ye.aspx\">http://msdn.microsoft.com/en-us/library/02y9a5ye.aspx MSVC记录为符合C90。
How can i enable the use of VLAs, variable length arrays as defined in C99, in MS Visual C++ or that is not possible at all?
Yes i know that the C++ standard is based on C89 and that VLAs are not available in C89 standard and thus aren't available in C++, but MSVC++ is supposed to to be a C compiler also, a behavior that can be switched on using the /TC compiler parameter (
Compile as C Code (/TC)
). But doing so does not seem to enable VLAs and the compiling process fails with the same errors when building as C++(Compile as C++ Code (/TP)
). Maybe MSVC++ C compiler is C89 compliant only or i am missing something(some special construct or pragma/define)?Code sample:
#include <stdlib.h> int main(int argc, char **argv) { char pc[argc+5]; /* do something useful with pc */ return EXIT_SUCCESS; }
Compile errors:
error C2057: expected constant expression
error C2466: cannot allocate an array of constant size 0
error C2133: 'pc' : unknown size
解决方案MSVC is not a C99 compiler, and does not support variable length arrays.
At http://msdn.microsoft.com/en-us/library/02y9a5ye.aspx MSVC is documented as conforming to C90.
这篇关于在MS的Visual C启用沃拉斯(可变长度数组)++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!