That old T() text macro

I’m still seeing people posting code snippets that use the old T(“foo”) style of writing strings, so thought I’d make a post here just to say DON’T USE IT ANY MORE!!

The fact that the T() macro ever existed was a nasty design mistake on my part… I added it many years ago when the String class could either use wide-chars or 8-bit chars internally, and I wanted to provide a way to write string literals which would be encoded in the same format as the Strings would be stored. This was an absolutely awful decision for more reasons than I can be bothered listing here, and I apologise!

(I also blame Microsoft, because I basically copied the idea from their dreadful _T macro, which I’d been using at the time…)

The recommended way to write a string literal now is simply to use a plain old ascii literal - this is both the most compact and the most efficient way to do so. The String class will accept wide character literals, but I very strongly advise you NOT to use them. If you need to embed any non-ascii characters in your code, the only reliable, cross-compiler way to do so is to encode them as utf-8, using escaped ascii literals. Trying to use wide-char L"foo" style strings relies on the compiler being aware of the encoding format that your source file is using, which is highly platform-dependent and will cause you pain. To make it easy to create c++ literals from unicode strings, I’ve added a handy utility to the Introjucer (on the Tools menu), which will generate the correct ascii escape sequences for some unicode text.

In the new modules branch, I’m removing the T macro by default - if you have old code that still uses it, you can re-enable it with the JUCE_DEFINE_T_MACRO flag, but your code will look cleaner if you just get rid of it.

If you want to strip your old code of the T() macro, there’s a helpful thread here with some regex tips: