ISO C forbids empty initializer braces in C

烈酒焚心 提交于 2019-12-23 19:23:36

问题


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?


回答1:


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

Will initialize all members of each struct to 0.




回答2:


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




回答3:


Try something like this:-

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

This will initialize all the members of struct to 0.



来源:https://stackoverflow.com/questions/13295872/iso-c-forbids-empty-initializer-braces-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!