I\'m wondering why I am getting a warning about initialization in one case, but not the other. The code is in a C++ source file, and using GCC 4.7 with -std=c++11
The only way to prevent that warning ( or error, if you or your organization is treating warning as error (-Werror
option)) is to memset()
it to init value. For example:
#include
#include
typedef struct {
int a;
int b;
char c[12];
} testtype_t;
int main(int argc, char* argv[]) {
testtype_t type1;
memset(&type1, 0, sizeof(testtype_t));
printf("%d, %s, %d\n", argc, argv[0], type1.a);
return 0;
}
Not very clean, however, seems like that for GCC maintainers, there is only one way to initialize a struct and code beauty is not on top of their list.