我是靠谱客的博主 英俊龙猫,这篇文章主要介绍c99数组长度规定,现在分享给大家,希望可以做个参考。

c99规定数组长度可以为变量,下面的代码合法:
int x ;
int array[x]

标准c++的规定不允许这样(没有具体查,多半我也看不懂c++的标准....)但gcc上面是允许的。
在这种情况下,gcc会调用alloca在栈上分配数据空间,alloca的manual如下:

NAME
       alloca - memory allocator

SYNOPSIS
       #include <alloca.h>

       void *alloca(size_t size);

DESCRIPTION
       The alloca function allocates size bytes of space in the stack frame of
       the caller.  This temporary space is automatically freed when the func-
       tion that called alloca returns to its caller.

RETURN VALUE
       The alloca function returns a pointer to the beginning of the allocated
       space.  If the allocation causes stack overflow, program  behaviour  is
       undefined.

最后

以上就是英俊龙猫最近收集整理的关于c99数组长度规定的全部内容,更多相关c99数组长度规定内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(2028)

评论列表共有 0 条评论

立即
投稿
返回
顶部