I have a c struct in header file:-
typedef struct sample
{
char *member1;
char **member2;
long *member3;
unsigned int member4;
} example;
I have declared a default typedef variable in same header file:-
const example defaultValue;
The definition of defaultValue is in c file:-
const example defaultValue =
{
NULL,
NULL,
NULL,
99
};
Now in a different c file if I do,
example example1 = defaultValue;
all members are assigned NULL as expected - but "unsigned int member4" is assigned value of 0 instead of 99. This is very strange because defaultValue.member4 is 99. Can somebody please explain this unusual behavior? Is there a better way to do a default struct initialization?