user707549
user707549

Reputation:

ISO C forbids empty initializer braces in C

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

Answers (3)

John Bode
John Bode

Reputation: 123548

Hello hello[6] = {{0}};

Will initialize all members of each struct to 0.

Upvotes: 10

Rahul Tripathi
Rahul Tripathi

Reputation: 172528

Try something like this:-

  Hello hello[6] = {{0}};

This will initialize all the members of struct to 0.

Upvotes: 5

R.. GitHub STOP HELPING ICE
R.. GitHub STOP HELPING ICE

Reputation: 215397

That's not valid C. The universal zero initializer in C is {0}, not {}.

Upvotes: 15

Related Questions