在MS的Visual C启用沃拉斯(可变长度数组)++? [英] Enabling VLAs(variable length arrays) in MS Visual C++?

查看:123
本文介绍了在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屋!

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