todd freed wrote:
Referring to section 5.21 of the docs - Designated Initializers
typedef struct
{
int a;
int b;
} foo;
Is there a way I can get this effect
foo myfoo = { .a = 0, .b = 0 };
without specifying each field? I just want the whole structure
initialized to zero.
You could do this:
foo myfoo = {0};
which means that the first member is explicitly initialized to zero and
the remaining members are implicitly initialized, also zero.
foo myfoo;
then I get 'use of uninitialized value' errors in valgrind.
Depending on where you define 'myfoo', this error might be correct. If
the definition is function-local, then the error is correct, otherwise -
if defined in the global scope - the members are implicitly initialized
to zero.
Andi