0

I have a simple C program that compiles fine under c99, but under ANSI it complains:

missing braces around initializer

The offending line is:

int myarr[3][3]={0};

Why is ANSI C complaining? I saw one posting saying to add additional { } around the { 0 } but that makes no sense to me...

(I'm compiling in CentOS in case it matters)

4

2 回答 2

3
int myarr[3][3]={0};

这是完全有效的 C,在这种情况下,警告只是编译器的一个指示。

如果你想摆脱警告,你可以这样做:

int myarr[3][3]={{0}};

或者-Wno-missing-braces如果您使用gccwith-Wall选项,也可以添加。

于 2013-01-20T21:29:12.863 回答
3

严格来说(在 ANSI C 下),如果要初始化多维数组,则应该附加大括号。例如,如果将每个元素初始化为特定值,则可以执行以下操作:

int myarr[3][3] = {{1,2,3},{4,5,6},{7,8,9}};
于 2013-01-20T21:32:45.123 回答