如何删除警告在GCC 4.6:缺少初始化[-Wmissing场-初始化] [英] How to remove the warning in gcc 4.6: missing initializer [-Wmissing-field-initializers]?

查看:1035
本文介绍了如何删除警告在GCC 4.6:缺少初始化[-Wmissing场-初始化]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在code:

  GValue value = { 0 };

给出以下警告:

缺少初始化[-Wmissing场-初始化]

missing initializer [-Wmissing-field-initializers]

我知道这是一个<一个href=\"http://stackoverflow.com/questions/1538943/why-is-the-compiler-throwing-this-warning-missing-initializer-isnt-the-stru\"><$c$c>gcc's BUG ;但有一些窍门去除呢?真的不是很好看这种虚幻的警告。但我不希望断电警告,因为它会隐藏真正的警告从我也是。虽然令人遗憾,但我无法将GCC升级到4.7(这里看起来就像是固定的)版本,但。

I know that's a gcc's BUG; but is there some trick to remove it? really not nice see such unreal warnings. But I don't want power off the warning because it will hidden real warnings from me too. A sorry, but I can't update my gcc to 4.7(where looks like it was fixed) version, yet.

推荐答案

使用 G_VALUE_INIT 初始化的GValue -s 。他们(私人)结构在 /usr/include/glib-2.0/gobject/gvalue.h 其中的#define G_VALUE_INIT 适当。

Use G_VALUE_INIT to initialize GValue-s. Their (private) structure is in /usr/include/glib-2.0/gobject/gvalue.h which #define G_VALUE_INIT appropriately.

我强烈的评估,这是海湾合作委员会的错误不同意。你问如果一个领域没有明确与 -Wmissing场初始化值初始化被警告,你会得到你应得的警告。

I strongly disagree with your assessment that it is GCC's bug. You ask to be warned if a field is not explicitly initialized with -Wmissing-field-initializers and you get the warning you deserve.

不幸的是 G_VALUE_INIT 未记录,但它是在这里。 code以

Sadly G_VALUE_INIT is not documented, but it is here. Code with

GValue value = G_VALUE_INIT;

有没有通用的解决方案,从来没有得到有关失踪字段初始化警告如果 -Wmissing场初始化值的问道。当你问这样的警告,你需要编译器警告每一个不完整的初始化的。事实上,标准要求比所有非显式初始化结构字段被清零,而 GCC 遵守的标准。

There is no universal solution to never get the warning about missing field initialization if -Wmissing-field-initializers is asked. When you ask for such a warning, you require the compiler to warn of every incomplete initializers. Indeed, the standard requires than all the non-explicitly initialized struct fields be zeroed, and gcc obeys the standard.

您可以使用诊断编译指示的像

#pragma GCC diagnostic ignored "-Wmissing-field-initializers"

但我的感觉是,你应该code小心,并明确初始化所有字段。你得到的警告,更多的是一种编码风格警告(也许你忘了场!)不是一个错误的警告。

But my feeling is that you should code with care, and explicitly initialize all the fields. The warning you get is more a coding style warning (maybe you forgot a field!) than a bug warning.

我也相信你自己的(公共)结构你应该的#define 初始化宏,如果这样的结构意图被初始化。

I also believe that for your own (public) struct you should #define an initializing macro, if such struct are intended to be initialized.

这篇关于如何删除警告在GCC 4.6:缺少初始化[-Wmissing场-初始化]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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