I want to initialize all struct members to 0. Common solution is to make something like this:
struct foo bar = {0}
I create this example:
#include <stdio.h>
struct Stru2 {
int c;
int d;
};
struct Stru1 {
int a;
Stru2 b;
};
int main()
{
struct Stru1 aaa = { 0 };
return aaa.b.c;
}
And I compile (gcc 4.6.3) it whit this parameters, to make sure how ANSI handle this
gcc -Wall -Wextra -pedantic -ansi main.cpp
And I got following warnings:
main.cpp: In function ‘int main()’:
main.cpp:36:28: warning: missing initializer for member ‘Stru1::b’ [-Wmissing-field-initializers]
The question is, why -Wextra, generate this warning? Maybe not always "= {0}", set all members to 0?