如何修复警告:在初始化程序周围丢失大括号?

编程入门 行业动态 更新时间:2024-10-26 02:32:08
本文介绍了如何修复警告:在初始化程序周围丢失大括号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 警告是由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}} ,它就会消失。您的选择是:

  • 忽略警告。
  • 操作C代码后生成 {{0}} 而不是 {0} 使用 sed 等。
  • 在Vala中声明数组 extern ,并在别处写入C定义。 (#2的永久版本。)
  • 做一些像 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:

  • Ignore the warning.
  • Manipulate the C code after generation to have {{0}} instead of {0} on that line using sed or the like.
  • Declare the array extern in Vala, and write the C definition elsewhere. (The permanent version of #2.)
  • 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.
  • 更多推荐

    如何修复警告:在初始化程序周围丢失大括号?

    本文发布于:2023-07-31 15:45:32,感谢您对本站的认可!
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:括号   初始化   程序

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!