I want to concat a string literal and char literal. Being syntactically incorrect, "abc" 'd' "efg"
renders a compiler error:
x.c:4:24: error: expected ',' or ';' before 'd'
By now I have to use snprift (needlessly), despite the value of string literal and the char literal being know at compile time.
I tried
#define CONCAT(S,C) ({
static const char *_r = { (S), (C) };
_r;
})
but it does not work because the null terminator of S
is not stripped. (Besides of giving compiler warnings.)
Is there a way to write a macro to use
"abc" MACRO('d') "efg"
or
MACRO1(MACRO2("abc", 'd'), "efg")
or
MACRO("abc", 'd', "efg")
?
In case someone asks why I want that: The char literal comes from a library and I need to print the string out as a status message.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…