I want to have a construct similar to this (invalid) one:
const uint8_t uArray[] = { uint8_t(sizeof(uArray)), 1, 2, 3 };
and the uArray[0] should be 4 and be filled automatically at the compile time, this is the situation for USB descriptors definition that are usually expressed as an array of bytes with the first byte value being the size in elements.
This theoretically should be possible because the array is initialized already but somehow I'm not able to express it.
Any suggestions to solve this are welcomed.
I read the specification http://open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf, and in paragraph 6.7.8.19 it states that the initialisation happens in initialisation list order, and in 6.7.8.22 it says "If an array of unknown size is initialized, its size is determined by the largest indexed element with an explicit initializer. At the end of its initializer list, the array no longer has incomplete type." To me, this suggests that at the time of initialisation of the first value, the type of the array (and its size) are still incomplete.
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