Placing a macro between two string literals

I know that you can associate a specific macro with a string literal like this

#define R "car"
const char * s1 = "foo"R; //s1="foocar"

But when I try to fit Rbetween two string literals like

#define R "car"
const char * s1 = "foo"R"bar"; //compile-time error

I get a compile time error error: stray 'R' in program. How can a second example be made to s1 = "foocarbar"?

+4
source share
1 answer

C ++ has a function called "string string literals" introduced by a letter R.

gcc explicitly supports C ++ type string literals in C as an extension. If you used a name other than Ryour macro, you would not have this problem.

Concatenation of string literals does not require string literal offsets. Instead of this:

#define R "car"
const char * s1 = "foo"R"bar"; 

:

#define R "car"
const char * s1 = "foo" R "bar";

C, gcc , , -std=c11, gcc .

, , , R .

+4

Source: https://habr.com/ru/post/1687589/


All Articles