它的编译器,我应该相信谁呢? [英] Which compiler should I trust?

查看:104
本文介绍了它的编译器,我应该相信谁呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这将是一些什么一个新手的问​​题,但我想在一个小运动在 C 的语言(没有的 C ++ 的)工作,我正在运行了一些问题。

This is going to be some what of a newbie question but I was trying to work on a small exercise in the C Language (not C++) and I was running into some issues.

说我想要的大小取决于某个参数的方法中使用数组:

Say I wanted to use an array within a method whose size depended on one of the arguments:

void someFunc(int arSize)
{
    char charArray[arSize];
    // DO STUFF
    ...
}

当我尝试编译这是内 .C 文件的的Visual Studio 2013 的我得到一个错误,指出非恒定数组大小不允许。但是,同样code工作的 $ C $个cblocks 的下一个GNU编译器中。我应该相信谁呢?这是正常的编译器表现得如此不同?我一直认为,如果你正在做的事情,一个编译器不喜欢你不应该摆在首位那样做,因为它不是一个标准。

When I try to compile this as a .c file within Visual Studio 2013 I get an error saying that a non-constant array size is not allowed. However the same code works within CodeBlocks under a GNU Compiler. Which should I trust? Is this normal for compilers to behave so differently? I always thought that if you're doing something that a compiler doesn't like you shouldn't be doing it in the first place because it's not a standard.

任何投入是很有用的!我来自一个背景中的的Python 的,我试图让更多的积极参与与数据结构与算法设计。

Any input is useful! I come from a Background in Python and I am trying to get more heavily involved in programming with Data-Structures and Algorithms.

我的平台是Windows,你可能会说。请让我知道,如果这个问题需要才可以回答更多的信息。

My platform is Windows as you can probably tell. Please let me know if this question needs more information before it can be answered.

推荐答案

变长数组( VLA 的)是的 C99 的功能和Visual Studio <一个href=\"http://blogs.msdn.com/b/vcblog/archive/2013/07/19/c99-library-support-in-visual-studio-2013.aspx\"相对=nofollow>直到最近没有不支持C99 ,我不知道这是否目前支持VLA在最新版本。海湾合作委员会在另一方面确实支持C99虽然href=\"http://gcc.gnu.org/c99status.html\" rel=\"nofollow\">没有完全 VLA作为C99模式以外的延伸,即使是在的 C ++

Variable length arrays(VLA) are a C99 feature and Visual Studio until recently did not support C99 and I am not sure if it currently supports VLA in the lastest version. gcc on the other hand does support C99 although not fully. gcc supports VLA as an extension outside of C99 mode, even in C++.

草案C99标准部分 6.7.5.2 数组声明第4段的:

[...]如果大小是整型常量前pression和元素类型有一个已知常数的大小,数组类型不是变长数组类型; ,否则,数组类型是一个可变长度的数组类型。

[...] If the size is an integer constant expression and the element type has a known constant size, the array type is not a variable length array type; otherwise, the array type is a variable length array type.

这篇关于它的编译器,我应该相信谁呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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