I would like to initialize a byte array with some byte values and a string literal in one go. Essentially the array is serialized representation of data structure like
struct foo {
uint8 param1;
uint8 stringLen;
const char * string;
uint8 param2;
};
though the API expects byte array and I have no control over that. The API expects the array to be statically initialized for sizeof operator to report actual size. I know it is possible to initialize an array with string literals OR specific bytes, though any attempt to initialize an array with both ends up in string literal being treated as a pointer address (what it is, no surprise here).
I was thinking about defining my own struct and initializing the array with that, but I don't believe structs or even string literals are compile-time serializable. I cannot seem to think of such syntax and am not even sure if that is possible at all. Any input appreciated.
The last resort could be initializing the array with something like array[] = "\x66oo", but that would only be marginally more maintainable than simple array[] = {0x66, 'o', 'o'}, both solutions require external (python?) generator.
constarray of the structure and it should be initialized at compile-time. Watch out for structure padding though, consult your compiler manual on how to pack structures without padding.char array[] = "a" "\x05" "Hello" "b";, but the resulting initalizer will be 9 bytes long instead of the intendeded 8 bytes )