I'm working on a USB device framework for an ARM microcontroller. USB uses a lot of variable-length structures, and I'd like to be able to declare them in my programs without calling constructors, allocating memory, etc. (Essentially, all the info is available at compile time; I just need to trick the compiler into putting it in the right place and doing type-checking.) The structures are conceptually similar to Pascal strings, where you have a length byte, followed by the appropriate number of characters, but some of the USB aggregates use wchar_t. Furthermore, some of the structures are referred to by an integer index, rather than directly by address. And...since the strings are often const, it would be nice to have them stored in .rodata.
Here's what I'd like to do: struct StringDescriptor { unsigned len; wchar_t str[0]; } __attribute__ (( packed )); struct DeviceDescriptor { // ... int MfgIndex; // ... } ; DeviceDescriptor myDev = { ... , StringDescriptor( "Acme Industries" ), ... } ; This would turn into some bytes in Flash containing 30 (== strlen ("Acme Industries") * sizeof(wchar_t)) and "A\0c\0m\0e\0 ....". The address of those bytes would be in an array of StringDescriptor pointers, and the index of the address in the array would go into the MfgIndex field of myDev. And this would all happen at compile time. Any chance of accomplishing this with gcc/g++, gas & gnu-ld? (I've gotten partway there with a cpp macro and asm() block, but perhaps there's a better way?) I'm sorely tempted to use a Perl preprocessor, but down that path lies madness... Thanks! _______________________________________________ help-gplusplus mailing list help-gplusplus@gnu.org http://lists.gnu.org/mailman/listinfo/help-gplusplus