Dear all, For some reason, I need to declare an array like that
#define STRING2_DESCRIPTOR_LENGTH 16 BYTE code product_string_descriptor[] = { STRING2_DESCRIPTOR_LENGTH, 0x03, 'U', 0x00, 'S', 0x00, 'B', 0x00, ' ', 0x00, 'H', 0x00, 'U', 0x00, 'B', 0x00 };
product_string_descriptor: DB end - $ DB 0x03, DB 'U', 0x00 DB 'S', 0x00 DB 'B', 0x00 DB ' ', 0x00 DB 'H', 0x00 DB 'U', 0x00 DB 'B', 0x00 end:
I do not know of a way to do this purely at compile time. Perhaps I'm overlooking something this morning, but this is as close as I got:
typedef struct { U8 length; U8 val; } StrDescHdr; U8 code pstr[] = { 'U', 0, 'S', 0, 'B', 0, ' ', 0, 'H', 0, 'U', 0, 'B', 0}; typedef struct { StrDescHdr Hdr; U8 code* value; } StrDesc; StrDesc code psd = { { sizeof(pstr) + sizeof(StrDesc), 3 }, pstr };
Hi Drew, Thanks for the suggestion of explicitly declare the size. But I think the compiler will not warn me if I have less initializer than the actual size. Most of the compiler will fill the rest of the array with zero. Am I right? Anyway, the compiler will still warn me if I supply more intializer than the actual size. So, I consider it as a better solution than before. Thanks again.