float myArray[myArraySize] = {1};
In the expression above only the first element is init with 1. How can you init all the elements with a value using a compound literals(not memset)?
I'm using GCC 4.2 on unix to compile.
This
float myArray[100] = {[0 ... 99] = 1.0};
is how you do it.
See Designated Initializers in the GCC docs which says:
To initialize a range of elements to the same value, write `[first ... last] = value'.
No, only the first element will be initialized to 1.0. The rest will be initialized, but to 0.0 per the C standard. Have a look at the C faq for some more examples.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With