C++中动态创建二维数组——尴尬的不支持C99的VC
来源:互联网 发布:centos 编译安装lamp 编辑:程序博客网 时间:2024/04/29 16:25
很多老外公布出来的算法代码常常是在Linux下实现的。很多时候会遇到动态数组定义。
举个二维数组的例子:
这是C99[6]标准中新添加的特性[3,4,5]。
C99 gives C programmers the ability to use variable length arrays, which are arrays whose sizes are not known until run time. A variable length array declaration is like a fixed array declaration except that the array size is specified by a non-constant expression. When the declaration is encountered, the size expression is evaluated and the array is created with the indicated length, which must be a positive integer. Once created, variable length array cannot change in length. Elements in the array can be accessed up to the allocated length; accessing elements beyond that length results in undefined behavior. There is no check required for such out-of-range accesses. The array is destroyed when the block containing the declaration completes. Each time the block is started, a new array is allocated.[4]
GCC编译器具有对C99标准比较完善的支持,而VC的编译器部分支持C99,但还不支持这种动态数组定义。
我的测试环境是VS 2008,不过至今VS2010都没有支持:
This version of Visual C++ is not conformant with the C99 standard.[8]
Thank you for your comment. There's no plans for VC to support C99.[9]
因此,要想在VC中编译老外的代码,要改写成动态创建的数组。
改法如下:
最后释放:
简单例子:
后话:
从MS Visual Studio开发小组的态度来看,近期之内,不会对C99进行完整的支持[7,8,9],这就意味着,可能在Windows下跑老外的Linux算法的时候涉及更多的代码改编。
因此,自然就要想到,如何让Visual Studio支持C99,我还没有去尝试,不过这里有篇帖子《VC里边怎么用C99》[10],方法是在VS中使用Intel C++编译器,抽时间可以试一下。
Referrences:
[1]Image Segmentation Code,http://cms.brookes.ac.uk/staff/PhilipTorr/Code/seg_page_1.htm
[2]C++中二维数组的动态创建与处理,http://www.programfan.com/blog/article.asp?id=25162
[3]可变长数组在GCC编译器中的实现,http://hi.baidu.com/wch20088082008/blog/item/1a7e09256b53c825d40742a7.html
[4]C语言变长数组之剖析,http://blog.chinaunix.net/space.php?uid=7897183&do=blog&cuid=220612
[5]我很满意C99的这几个特性(2) —— 定义变量和不定长数组,http://hi.baidu.com/zotin/blog/item/ca0f9023972c0f49ac34deb3.html
[6]C99 - Wikipedia, the free encyclopedia,http://en.wikipedia.org/wiki/C99
[7]Visual Studio support for new C / C++ standards?,http://stackoverflow.com/questions/146381/visual-studio-support-for-new-c-c-standards
[8]C Run-Time Libraries,http://msdn.microsoft.com/en-us/library/abx4dbyh.aspx
[9]C99 support ,http://connect.microsoft.com/VisualStudio/feedback/details/653336/c99-support
[10]VC 里边怎么用C99?,http://playmov.cn/post-16.html
- C++中动态创建二维数组——尴尬的不支持C99的VC
- VC中动态创建二维数组的方法
- C语言中动态二维数组的创建
- C语言中动态二维数组的创建
- 【C++】动态二维数组的创建
- C++中二维动态数组的创建
- C中动态二维数组的获取
- C中动态二维数组的生成
- 二维数组的动态创建
- 二维数组的动态创建
- 二维数组的动态创建
- 二维动态数组的创建
- c语言动态创建二维数组的方法
- C/C++中动态创建和释放二维数组的两种办法
- C++中二维数组的动态创建与处理
- C++中二维数组的动态创建于处理(zzl
- 关于JAVA中动态创建二维数组的“技巧”
- c++中try_catch的使用,二维数组动态创建
- REHL4下sendmail配置简要说明
- 关于Flex的MessageBroker Endpoints channels的配置运用
- 我的vim配置
- 关于#/##在宏定义中的用法
- 海量数据处理:十道面试题与十个海量数据处理方法总结
- C++中动态创建二维数组——尴尬的不支持C99的VC
- Google的十个核心技术
- java Socket服务端
- 那又怎样!
- JAVASCRIPT 中 日期时间相减的方法
- Google Chrome现在支持Web Sockets
- 初识SQL数据库
- Parallel to Serial (可以设置任意位宽)
- bash 脚本编程