The code
GValue value = { 0 };
gives the following warning:
missing initializer [-Wmissing-field-initializers]
I know that’s a GCC bug, but is there some trick to remove it? It is really not nice see such unreal warnings. But I don’t want power off the warning because it will hide real warnings from me too. And sorry, but I can’t update my GCC to 4.7 (where looks like it was fixed) version, yet.
Use
G_VALUE_INITto initializeGValue-s. Their (private) structure is in/usr/include/glib-2.0/gobject/gvalue.hwhich#define G_VALUE_INITappropriately.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-initializersand you get the warning you deserve.Sadly
G_VALUE_INITis not documented, but it is here. Code withThere is no universal solution to never get the warning about missing field initialization if
-Wmissing-field-initializersis 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 initializedstructfields be zeroed, andgccobeys the standard.You could use diagnostic pragmas like
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.
I also believe that for your own (public)
structyou should#definean initializing macro, if suchstructare intended to be initialized.