1

Is there a way to have a single source file define compile-time string literals in both Java and C++ (and ideally also Objective-C) ?

For C++ and Objective-C it's relatively easy using #if __OBJC__:

#if __OBJC__
#define _str_literal_ @
#else
#define _str_literal_
#endif

#define MY_TOKEN _str_literal_"hello world"

#undef _str_literal_

But for C++ / Java I suspect some sort of code-generating tool would be required.

Edited to reflect Dale's advice.

orion elenzil
  • 4,484
  • 3
  • 37
  • 49

0 Answers0