55

警告是由 vala 生成的 c 代码产生的。

警告:初始化器周围缺少大括号

代码有效,但警告很烦人。警告引用的 vala 代码是

struct Position {uint x; uint y;}
private static Position positions[8];

生成的 C 代码是

static Position det_positions[8] = {0};

我尝试了六种不同的方式初始化位置,但似乎无法获得满足警告的语法。这是GCC 错误 53119还是有办法修复它?

4

2 回答 2

73

是的,这似乎与GCC 错误 53119有关。如果您将 C 声明更改为{{0}}. 您的选择是:

  1. 忽略警告。
  2. 在生成后操作 C 代码,{{0}}而不是{0}在该行上使用sed等。
  3. 在 Vala 中声明数组extern,并在别处编写 C 定义。(#2 的永久版本。)
  4. 做类似的事情struct foo { int bar; Position positions[8]; } static foo position_holder,然后{0}将进行初始化position_holder.bar,这很好,警告消失了。
于 2012-12-07T06:50:06.883 回答
17

当设置了 -Wall 编译器标志的多维数组被视为线性数组(尽管它仍然正确并且代码运行完美)时,也会出现此警告。

例如

char array[5][10][2] = {\
"0","0","0","0","0","0","0","0","0","0",\
"1","1","1","1","1","1","1","1","1","1",\
"2","2","2","2","2","2","2","2","2","2",\
"3","3","3","3","3","3","3","3","3","3",\
"4","4","4","4","4","4","4","4","4","4" };

这将生成警告。

执行以下更改以删除警告,如下所示

char array[5][10][2] = {\
{"0","0","0","0","0","0","0","0","0","0" },\
{"1","1","1","1","1","1","1","1","1","1"},\
{"2","2","2","2","2","2","2","2","2","2"},\
{"3","3","3","3","3","3","3","3","3","3"},\
{"4","4","4","4","4","4","4","4","4","4"} };

如果我错了,请纠正我。

于 2014-02-19T07:17:58.457 回答