0

The macro #define STR16(x) L ## x works when applied to string literals:

STR16("Hello")     // fine, this is translated to L"Hello"

but not to variables:

STR16(x)     // fails, this is translated to Lx, and the variable Lx doesn't exist

In line 200 of this useful library, there is a bug:

Parameter* param = new RangeParameter( STR16(p->GetNameForHost()), ...

will be translated to

Parameter* param = new RangeParameter( Lp->GetNameForHost(), ...

which fails, because Lp is an undeclared identifier.

How to do the same than adding L to a string literal, to a string variable const char * ?

Basj
  • 41,386
  • 99
  • 383
  • 673
  • How to convert narrow to wide, depends on the narrow encoding. But since wide in practice is some Unicode encoding, and since Unicode is a superset of Latin-1 which is a superset of ASCII, if the narrow encoding is either ASCII or Latin-1 then you can just widen each code point. – Cheers and hth. - Alf Sep 28 '16 at 19:12
  • Note that the name `STR16` is platform-dependent: it's true in Windows, but mostly not elsewhere. – Cheers and hth. - Alf Sep 28 '16 at 19:12
  • Looks like you need something like [this](http://stackoverflow.com/questions/30409350/convert-const-char-to-const-wchar-t) – NathanOliver Sep 28 '16 at 19:14
  • 3
    Have you filed an issue on GitHub for this? If not, you probably should. – Mad Physicist Sep 28 '16 at 19:16
  • @MadPhysicist I just did: [STR16 issue in IPlugVST3.cpp](https://github.com/olilarkin/wdl-ol/issues/61). – Basj Sep 28 '16 at 19:34
  • 1
    If you get an answer here first, you can submit a patch to the library. If the library gets fixed first, let us know how by answering your own question. Either way, good work. – Mad Physicist Sep 29 '16 at 14:30

0 Answers0