I have an array that's used in a communication protocol (a USB device descriptor). This protocol calls for the array size in the array header. So I would like to do that (which is forbidden):
static uint8_t array[]= {
TYPE,
sizeof(array),
other data...
};
The array being in a read only part of the memory, I can't override the relevant cell after the fact, and I'm not really willing to copy it to override the cell (it's in a minimal embedded system). I need it to look like "on the wire" because it will go through DMA.
Is there some kind of magic that could work around this limitation? I'm willing to use C99 or GNU extensions. I won't switch just for that, but I'm curious about a C++ solution too.
static uint8_t array[18] = ...is presumably no more helpful a solution than 'why don't you just type the size of the array by hand and not use sizeof'?const.