RFC: adding a #define G_VALUE_INIT for initializing GValue on the stack



When a GValue is declared on the stack, the large code base I work
with usually does not properly initialize the struct. (e.g. "GValue v
= {0,};") This causes gcc to print warnings when 'gcc -Wall -Wextra'
is used due to -Wmissing-braces and -Wmissing-field-initializers.

I checked gvalue.h and I don't see a #define in there containing the
proper initializer list for a GValue to prevent gcc warnings. Rather
than duplicating "GValue v = {0, {{0}}};" everywhere, I'd like the
following to be added:

#define G_VALUE_INIT {0,{{0}}}

That way, code everywhere could simple use "GValue v = G_VALUE_INIT;"
and be sure that warnings will not be generated and that the
initializer list will always be kept up to date in the unlikely case
that it ever changes.

These are the warnings (or errors with -Werror) that print out if this
is not done correctly:

// if {0, } is used
error: missing initializer for member '_GValue::data'
// if {0, 0} is used
error: missing braces around initializer for '_GValue::<anonymous union> [2]'
// if {0, {0}} is used
error: missing braces around initializer for '_GValue::<anonymous union>'

Does anyone have objections to adding this, or is a better name preferred?

-Andrew


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]