加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

C89中的可变长度数组?

发布时间:2020-12-16 03:22:08 所属栏目:百科 来源:网络整理
导读:我读过C89不支持可变长度的数组,但下面的实验似乎反驳: #include stdio.hint main(){ int x; printf("Enter a number: "); scanf("%d",x); int a[x]; a[0] = 1; // ... return 0;} 当我这样编译(假设文件名是va_test.c): gcc va_test.c -std=c89 -o va_tes
我读过C89不支持可变长度的数组,但下面的实验似乎反驳:
#include <stdio.h>

int main()
{
   int x;
   printf("Enter a number: ");
   scanf("%d",&x);
   int a[x];
   a[0] = 1;
   // ...
   return 0;
}

当我这样编译(假设文件名是va_test.c):

gcc va_test.c -std=c89 -o va_test

有用…

我失踪了什么:-)

解决方法

GCC始终支持可变长度数组AFAIK.将-std设置为C89不会关闭GCC扩展…

编辑:其实如果你在这里查:

http://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html#C-Dialect-Options

在-std =你会发现如下:

ISO C90 programs (certain GNU
extensions that conflict with ISO C90
are disabled). Same as -ansi for C
code.

密切注意“确定”一词.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读