define string at compiler options

2.7k views Asked by At

Using Tornado 2.2.1 GNU

at C/C++ compiler options I'm trying to define string as follow: -DHELLO="Hello" and it doesn't work (it also failed for -DHELLO=\"Hello\" and for -DHELLO=\\"Hello\\" which works in other platforms) define value -DVALUE=12 works without issue.

does anybody know to proper way to define string in Tornado?

1

There are 1 answers

0
EmDroid On

The problem with such a macro is, that it normally isn't a string (in the C/C++ sense), just a preprocessor symbol. With numbers it works indeed, because preprocessor number can be used in C/C++ as is, but with string symbols, if you want to convert them to C/C++ strings (besides adding the escaped quotes) you need to "stringize" them.

So, this should work (without extra escaped quotes):

#define _STRINGIZE(x) #x
#define STRINGIZE(x) _STRINGIZE(x)

string s = STRINGIZE(HELLO)

(note the double expansion to get the value of the macro stringized, i.e. "Hello", instead of the macro name itself, i.e. "HELLO")