我可以使用C ++ 03和C ++ 11 C变量长度数组? [英] Can I use a C Variable Length Array in C++03 and C++11?

查看:212
本文介绍了我可以使用C ++ 03和C ++ 11 C变量长度数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C有所谓的变长数组一个很酷的功能。它在C90及更高版本,它允许推迟阵列,直到运行时的大小。请参阅GCC手册变长的6.19阵列。

C has a really cool feature called variable length arrays. Its available in C90 and above, and it allows deferring the size of the array until runtime. See GCC's manual 6.19 Arrays of Variable Length.

我在C ++中工作。在 STD = C ++ 11 ,我赶上一个编译失败,由于在Cygwin下使用的alloca 的。我想如果可能的话,切换到变长数组。我也想尽量避免的std ::矢量的std ::阵列,因为我想留出内存管理器。我相信,每一点帮助,所以我很高兴把这些机会(有些人认为窥视孔)。

I'm working in C++. At std=c++11, I'm catching a compile failure due to the use of alloca under Cygwin. I want to switch to variable length arrays, if possible. I also want to try and avoid std::vector and std::array because I want to stay out of the memory manager. I believe every little bit helps, so I'm happy to take these opportunities (that some folks consider peepholes).

我可以使用可变长度数组中的C ++ 03和C ++ 11?

Can I use a variable length array in C++03 and C++11?

推荐答案

VLA s为不标准的C ++ 03或C ++ 11,所以你最好避免他们,如果你想写严格符合标准的code(以及使用如的std ::矢量,它一般采用堆它的数据 - 但你可能会使用自己的分配...)

VLAs are not in standard C++03 or C++11, so you'll better avoid them if you want to write strictly standard conforming code (and use e.g. std::vector, which generally use heap for its data - but you might use your own allocator...).

然而,一些C ++编译器(最近 GCC &放大器;的)正在接受沃拉斯作为扩展。

However, several C++ compilers (recent GCC & Clang) are accepting VLAs as an extension.

这是灵活数组成员的是相同的;他们是不是在C ++(仅在C)的标准,但一些编译器接受。

It is the same for flexible array members; they are not standard in C++ (only in C) but some compilers accept them.

的DynArray -s没有进入C ++ 11的标准..

dynarray-s did not get into the C++11 standard...

这篇关于我可以使用C ++ 03和C ++ 11 C变量长度数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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