Hacker News new | ask | show | jobs
by MaxBarraclough 1597 days ago
If I understand correctly, reading [0], in C99 (or later) you can do that with

    struct MyStruct foo = {};
This has the effect of initializing all members to zero (or, more precisely, the value which is the same as for objects that have static storage duration [0]).

[0] https://gcc.gnu.org/onlinedocs/gcc/Designated-Inits.html

See also Stop Memsetting Structures: https://news.ycombinator.com/item?id=19766930

1 comments

You need to put something in those braces. An empty initializer list is not allowed by C99 or C11. That being said, you only need to put ONE thing in there, the rest will then be initialized as you described.
Thanks, StackOverflow confirms you're correct. [0]

That's what I get for using GCC as an approximation of the C standard. (By default, GCC permits empty initializer lists.)

[0] https://stackoverflow.com/a/17589839/