For gcc, this warning only shows up with -Wextra (-Wall doesn't show it).
In the following nested structure (x) I could only get the warning to go away by doing this:
Code:
struct X x = { 0, 0, 0, {0, 0} };
Interestingly, there's a difference between doing this and using memset, in that the "holes" in the structure are not zeroed with the initializer method, as demonstrated by this program:
Code:
#include <stdio.h>
struct Y {
char d;
int e;
};
struct X {
char a;
int b;
double c;
struct Y y;
};
int main(void) {
struct X x = { 0, 0, 0, {0, 0} };
char *p, *pend = (char*)&x + sizeof(x);
for (p = (char*)&x; p < pend; p++)
if (*p != 0)
printf("%d\n", p - (char*)&x);
return 0;
}