I have this struct in C below that I want to initialize to all zero. How do I get rid of the missing braces warning?
typedef struct {
uint32_t incoming[FRAME_TYPE_MAX];
uint32_t outgoing[FRAME_TYPE_MAX];
uint32_t timeouts;
uint32_t crc_errors;
} pkt_t;
static pkt_t stats = {0};
From "info gcc"
You may be able to combine these initializers to allow gcc-specific initialization of your arrays without having to specify every element in the array. Or...you can set a flag and initialize it at runtime when necessary, or...you can discover whether the variable is in BSS or not and may be automatically zeroed (is this on the stack in a function or in global memory).
Set this gcc compiler flag: -Wno-missing-braces
This is GCC bug # 53119:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119
If you want to see it fixed, post a followup to the bug report indicating that it's a problem for you.
If it is a global variable or a local static one, it's automatically initialized. So, simply:
One way is to initialize every member of the struct inside the braces, rather than relying on the implicit zero filling. For array members, you need another {} which is likely causing the warning. Another is to just disable the warning, though this isn't recommended as it can also catch legitimate bugs.