How to concatenate a character constant into a string. C -
If I have a constant character defined in C, can I include it in a line in the string ?
#ifdef WIN32 # define SEP '\\' #define ALTSEP '/' #sese # define SEP '/' #define ALTSEP '\\' #endif #define SOME_STRING_LITERAL "foo "/ * code snippet * / / * desired string:" prefix_fu / bar "* / const four * path =" prefix_ "SOME_STRING_LITERAL SEP" bar "; Of course, this fails because sep is not defined as a string, but there is no way to sep Insert? Or would I need any other definition, such as #define SEP_STR "/" .
I do not think you can do it in C.
The main problem is that the " symbol is something original that it knows the pre-processor should do or do it as a pre-processing token. # Strings with operator will not help. Even if you
#define STRINGINIZE (X) #x #define CHAR_TO_STR (ch) STRINGINIZE (ch) < / Pre> and then open it as
const char * path = "prefix_" SOME_STRING_LITERAL; CHAR_TO_STR (SEP) "bar"; This will not be good for you, because you prefix_ You can not do this by: const char * path = "prefix_" SOME_STRING_LITERAL CHAR_TO_STR (SEP) [1] "foo` \ times Bar ";
Because we had it in the first place and it will not be the ompili.
In addition to this, you do not have solution based on adding pre-processor tokens , Because is more fundamental than " ## . So the only solution seems to declare the letter as string literals.
Comments
Post a Comment