Odd use of curly braces in C

Assuming that MyRecorder is a struct, this sets every member to their respective representation of zero (0 for integers, NULL for pointers etc.).

Actually this also works on all other datatypes like int, double, pointers, arrays, nested structures, …, everything you can imagine (thanks to pmg for pointing this out!)

UPDATE: A quote extracted from the website linked above, citing the final draft of C99:

[6.7.8.21] If there are fewer initializers in a brace-enclosed list
than there are elements or members of an aggregate, […] the remainder of the
aggregate shall be initialized implicitly the same as objects that
have static storage duration.

Leave a Comment