How to repair warning: missing braces around initializer?

我是研究僧i 提交于 2019-11-28 20:05:52
apmasell

Yes, this appears to be related to GCC bug 53119. It goes away if you change the C declaration to {{0}}. Your options are:

  1. Ignore the warning.
  2. Manipulate the C code after generation to have {{0}} instead of {0} on that line using sed or the like.
  3. Declare the array extern in Vala, and write the C definition elsewhere. (The permanent version of #2.)
  4. Do something like struct foo { int bar; Position positions[8]; } static foo position_holder and {0} will then be initialising position_holder.bar which is fine and the warning goes away.

This warning also appears when a multi-dimensional array is treated as a linear array ( although it is still correct and the code runs perfectly ) with -Wall compiler flags set.

For example

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" };

This will generate the warning.

Do the following changes to remove the warnings as shown below

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"} };

Please do correct me if I am wrong.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!