C中文件范围内可变修改的数组 [英] variably modified array at file scope in C
本文介绍了C中文件范围内可变修改的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些这样的代码:
static int a = 6;
static int b = 3;
static int Hello[a][b] =
{
{ 1,2,3},
{ 1,2,3},
{ 1,2,3},
{ 1,2,3},
{ 1,2,3},
{ 1,2,3}
};
但是当我编译它时,它说错误:
but when I compile it, it says error:
在文件范围内可变修改Hello"
variably modified 'Hello' at file scope
怎么会这样?我该如何解决?
how could this happen? and how could I fix it?
推荐答案
你不能将静态数组的大小作为变量给出
You can not have static array which size is given as a variable
这就是为什么常量应该是 #define
d:
That's why constants should be #define
d:
#define a 6
这样预处理器会将a
替换为6
,使其成为有效的声明.
This way preprocessor will replace a
with 6
, making it valid declaration.
这篇关于C中文件范围内可变修改的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文