I've seen some old code that looks like this: char foo[100] = { 0 };. Something similar happens with structs, like so: STRUCT st = { 0 };. The intention in both cases is clear, namely to zero-initialize the respective variables. As such, char foo[100] {}; and STRUCT st {}; would have been more idiomatic.
My question is: should the code with <variable> = { 0 } be expected to achieve the same outcome? I've tested this with release-build binaries and the elements appear to be zero-initialized, but is this guaranteed by the standard? It seems to me that <variable> = { 0 } should only guarantee for the first element of the variable (array element or struct member) to be zero.
Also, what behavior is indicated by the similar declarations char foo[100] = {}; and STRUCT st = {}?
(Motivation behind this question is that I'd change all the declarations to the idiomatic form, but if there is no guarantee of zero-initialization then the issue is something more serious and worth opening a ticket over.)
STRUCT? - juanchopanza= { 0 }was the only form of initialization allowed in C, C++11 allows empty braced list and uniform initializationstruct s {};Note that there are underwater reefs with its use, uniform initialization may do not what you expect with non-trivial classes that acceptinitializer_list. E.g.vector<int> v {3};creates vector containing one element with value of 3. - Swift - Friday Pie