I would like to the #define directive inside of a quotation. Here’s the problem:
There is a built-in function in the embedded platform that I’m using that takes literal assembly code as a string. I would like to wrap this into a macro.
__asm__("goto 0x2400");
The above built-in function the processor jumps to the code at location 0x2400 and starts executing at that address (for those wondering, I’m writing a bootloader which is why this is necessary). Because the address is in the string, I cannot easily replace it. I need a way to make the function generic so that I can start executing code at any address. For example:
#define ASM_GOTO __asm__("goto X")
This will not result in a correct text replacement because the X is in quotes. Is there a way around this?
This has a slight problem, though:
Results in
__asm__("goto " "MAGIC_ADDRESS");, which I expect isn’t what you want.So,
is probably more like it, since in the expansion of
ASM_GOTO,Xgets expanded beforeSTRINGIZEacts on it.If you didn’t already know, be aware that although the result from the preprocessor is
"goto " "0x2400"(two string literal tokens), they’re combined during compilation into a single string literal (5.1.1.2/6 of C99). This occurs after macros are expanded (4), but before semantic analysis (7).