I have a useful macro:
#define TEXT(x) L##x
#define TEXT(x) x
Ie using the L prefix to 'widen' the string literals. This part alone works great.
Now, I want to do this:
TEXT("foo" "bar" "baz")
which ideally, #ifdef _UNICODE, would yield:
which is what I want out of all this - a concatenated, wide string.
The problem is that C preprocessors expand the TEXT macro and do the token-pasting first, yielding this:
L"foo" "bar" "baz"
and only afterwards does the C compiler do concatenation of the adjacent string literals. At this stage, one C compiler
emits the error "concatenating mismatched wide strings"; other C compilers seem to do what I want - if any string is wide, they are all 'widened', then they are concatenated.
What I really want is for the string-literal concatenation pass to be done first, yielding:
and only afterwards, the token-pasting operator will prepend L, yielding:
At the moment, I am forcing things to happen the way I want by doing:
#define TEXT2(a, b) TEXT(a) TEXT(b)
#define TEXT3(a, b, c) TEXT(a) TEXT(b) TEXT(c)
... and so on. This works, forcing the L to be prepended first (but to each string seperately), so that all of the strings are wide by the time the compiler sees them, so that they can always be legally concatenated by any compiler.
However I will soon reach TEXT<INT_MAX>, and it is a kluge that hurts my eyeballs each time I scroll past it.
Apparently, under C89, the value of "foo" L"bar" is undefined, whereas later C flavours define it to be identical to L"foo" L"bar". I suppose this is why I only encounter the problem with one specific compiler. But I can't upgrade the compiler in question (because it's a closed source POS that I am forced to use and cannot change).
Does anybody know of another way to accomplish what I want?