Can a C pre-processsor macro be used to generate the string below where size is the result of the sizeof macro?
const char testXmlElement [] = "< xs:element name="count" size="4" \>";
Use of the stringizing macro generates the result size=”sizeof(int)” instead of the desired result, size=”4″.
#define xstr(s) str(s) #define str(s) #s const char testXmlElement[] = "<element size=\"" xstr(sizeof(int)) "\"" " \\>";
My intention was to create an XML schema in an embedded microcontroller application using both the sizeof() and offsetof() macros. The resulting schema would be used to de-serialize XML to nested C data structures.
Thanks in advance,
I don’t believe so. The preprocessor runs before the compiler, and
sizeofis interpreted by the compiler.