FINAL UPDATE:
After reading many related questions and answers it seems to me the answer is simple, albeit disappointing: It is impossible to concatenate string literals in preprocessor. Adding macro to the mix does not change this, it only muddles the picture.
I'll delete this question later, unless somebody says the above is wrong.
================
I am trying to define a string literal from several string literals and some macros.
Yes, I know that adjacent string literals are concatenated by the compiler. There are hundreds of questions "how to concatenate strings in preprocessor" here and they all have pretty much the same answer. But it does not answer the actual question.
I am trying to do something like this (the code below is just a hint, it needs a second layer of parameterized macro to actually compile)
#define A 1
#define B 2
#define STR1 "Up\r" #A "\r" #B "\r"
#define STR2 "Down\r" #B "\r" #A "\r"
char* strings[] = { STR1, STR2 };
In this example, when I examine STR1 macro expansion in IDE, I would like to see "Up\r1\r2\r"
, not "Up\r" "1" "\r" "2" "\r"
.
UPDATE:
The example below shows that IDE is perfectly capable of displaying merged macro, in this case macro expansion on STR1 shows "12". It is only when I am trying to add string literals to the mix I am having problems.
#define CON1(a,b) a ## b
#define CON2(a,b) CON1(a,b)
#define STR1 CON2(A,B)
My question is this: Is it possible to concatenate strings and macros in preprocessor to get final string literal as one unbroken string?
No. Concatenation of adjacent string literals occurs in Phase 6, while preprocessing occurs in Phase 4.
You did not mention which IDE you were using, but you could submit a feature request that expanded macros optionally have their strings concatenated. It should not be the default option, however, because then the IDE would be lying to you about what the macros precisely expand to.