Search code examples
cstringmacrosc-preprocessorstringification

Concatenate C macro definition string to literal strings


Let the first row be:

#define TAG_LEN 32

Now, I need to concatenate it with a literal string constant; something like that:

puts("Blah" [insert your answer] TAG_LEN); // I need "Blah32".

Solution

  • #define STR_NOEXPAND(tokens) # tokens
    #define STR(tokens) STR_NOEXPAND(tokens)
    puts("Blah" STR(TAG_LEN));