You'll want to use the preprocessor's 'stringizing' operator, #
, and probably the 'token pasting' operator, '##':
#define STRINGIFY2( x) #x
#define STRINGIFY(x) STRINGIFY2(x)
#define PASTE2( a, b) a##b
#define PASTE( a, b) PASTE2( a, b)
#define PRINTTHIS(text) \
NSLog(PASTE( @, STRINGIFY(text)));
I'm not sure if Objective-C requires the '@' to have no whitespace between it and the opening quote - if whitespace is permitted, drop the PASTE() operation.
Note that you'll need the goofy 2 levels of indirection for STRINGIFY()
and PASTE()
to work properly with macro parameters. And it pretty much never hurts unless you're doing something very unusual (where you don't want macro parameters expanded), so it's pretty standard to use these operators in that fashion.