Reputation:
I have a struct like this:
typedef struct
{
int a;
int b;
int c;
int d;
} Hello;
then I declare it in this way:
Hello hello[6] = {};
Then I got this warning: ISO C forbids empty initializer braces, anyhow I think I need to initialize it, how to do it in the right way?
Upvotes: 10
Views: 6023
Reputation: 123548
Hello hello[6] = {{0}};
Will initialize all members of each struct to 0.
Upvotes: 10
Reputation: 172528
Try something like this:-
Hello hello[6] = {{0}};
This will initialize all the members of struct to 0.
Upvotes: 5
Reputation: 215397
That's not valid C. The universal zero initializer in C is {0}
, not {}
.
Upvotes: 15