如何修复警告:在初始化程序周围丢失大括号? [英] How to repair warning: missing braces around initializer?

查看:1519
本文介绍了如何修复警告:在初始化程序周围丢失大括号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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


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

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

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

生成的C代码是

  static Position det_positions [8] = {0}; 

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

解决方案

是的,这似乎与 GCC错误53119 。如果将C声明更改为 {{0}} ,它就会消失。您的选择是:


  1. 忽略警告。

  2. 操作C代码后生成 {{0}} 而不是 {0} 使用 sed 等。

  3. 在Vala中声明数组 extern ,并在别处写入C定义。 (#2的永久版本。)

  4. 做一些像 struct foo {int bar;职位[8]; } static foo position_holder {0} 然后会初始化 position_holder.bar ,它是罚款和警告消失。


The warning is produced by the c code generated by vala.

warning: missing braces around initializer

The code works but the warning is annoying. The vala code referenced by the warning is

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

The generated C code is

static Position det_positions[8] = {0};

I've tried initializing positions half a dozen different ways but can't seem to get the syntax to satisfy the warning. Is this GCC bug 53119 or is there a way to fix it?

解决方案

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.

这篇关于如何修复警告:在初始化程序周围丢失大括号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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