If I have a struct like this:
typedef struct
{
unsigned char c1;
unsigned char c2;
} myStruct;
What would be the easiest way to initialize this struct to 0?
Would the following suffice?
myStruct _m1 = {0};
or Would I need to explicitly init each member to 0?
myStruct _m2 = {0,0};
The first is easiest(involves less typing), and it is guaranteed to work, all members will be set to
0[Ref 1].The second is more readable.
The choice depends on user preference or the one which your coding standard mandates.
[Ref 1] Reference C99 Standard 6.7.8.21:
Good Read:
C and C++ : Partial initialization of automatic structure