在C89变长数组? [英] Variable-length arrays in C89?

查看:564
本文介绍了在C89变长数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读过,C89不支持变长数组,但下面的实验似乎反驳说:

I've read that C89 does not support variable-length arrays, but the following experiment seems to disprove that:

#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

When I compile as such (assuming filename is va_test.c):

gcc va_test.c -std=c89 -o va_test

它的工作原理...

It works...

我在想什么? : - )

What am I missing? :-)

推荐答案

GCC始终支持变长数组AFAIK。 -std设置为C89不关闭GCC的扩展...

GCC always supported variable length arrays AFAIK. Setting -std to C89 doesn't turn off GCC extensions ...

编辑:事实上,如果你点击这里:

In fact if you check here:

<一个href=\"http://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html#C-Dialect-Options\">http://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html#C-Dialect-Options

在-std =你会发现以下内容:

Under -std= you will find the following:

ISO C90程序(某些 GNU
  扩展与ISO C90冲突
  被禁用)。同-ansi对C
  code。

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

狠抓词一定的。

这篇关于在C89变长数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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