(no title)
stevejones | 10 years ago
uint32_t array[10] = {0};
Does not initialise every element to 0 in the way it would seem to. To see the difference contrast the difference you get when you a) remove the initialiser and b) replace the initialiser with {1}.
Arnavion|10 years ago
Yes it does, since atleast C99. As for the others:
a) Removing the initializer will leave the values undefined.
b) Using an initializer of { 1 } will initialize the first element to 1 and the rest to 0.
stevejones|10 years ago
{} initialises all elements to 0.
{0} initialises the first element to 0 and the rest to 0.
The latter form just introduces confusion.
to3m|10 years ago
C++ lets you do "uint32_t array[10]={}", which is something C should allow as well, really. But it doesn't.
jzwinck|10 years ago
stevejones|10 years ago
jamessu|10 years ago
I think the real issue here is the inconsistency between C standards on details like this. If you can always assume that your code is built with c99 or later, then use all of its features, but in many cases that's not a realistic assumption.
DerekL|10 years ago
“If there are fewer initializers in a list than there are members of an aggregate, the remainder of the aggregate shall be initialized implicitly the same as objects that have static storage duration.”
gvb|10 years ago
The problem I've had (and you probably are referring to) is embedded systems that may not properly zero bss. I've also had problems in embedded systems trying to place "array[10] = {0};" into a specific non-bss section (that was really annoying).
In my experience, TFA is good practices generally, but will have problems in corner cases that you run into in deeply embedded systems.
heinrich5991|10 years ago