Reputation: 5122
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.
Upvotes: 2
Views: 76
Reputation: 5307
If you would not use an array, but a struct, which it looks like you really want, then it would be possible:
typedef struct
{ int type, size, other;
} pack_t;
static pack_t a =
{ 10, sizeof(a), 11
};
Upvotes: 3