How to remove the warning in gcc 4.6: missing initializer [-Wmissing-field-initializers]?

Jack picture Jack · Nov 14, 2012 · Viewed 13.9k times · Source

The code:

  GValue value = { 0 };

Give the following warning:

missing initializer [-Wmissing-field-initializers]

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.

Answer

Jonathan Leffler picture Jonathan Leffler · Nov 14, 2012

You could use:

-Wno-missing-field-initializers

to inhibit that warning specifically. Conversely, you could make it into an error with:

-Werror=missing-field-initializers

Both of these work with GCC 4.7.1; I believe they work with GCC 4.6.x too, but they don't work with all earlier versions of GCC (GCC 4.1.2 recognizes -Wno-missing-field-initializers but not -Werror=missing-field-intializers).

Obviously, the other way to suppress the warning is to initialize all fields explicitly. That can be painful, though.