What’s the current best practice for handling generic text in a platform independent way?
For example, on Windows there are the ‘A’ and ‘W’ versions of APIs. Down at the C layer we have the ‘_tcs’ functions (like _tcscpy) which map to either ‘wcscpy’ or ‘strcpy’. And in the STL I’ve frequently used something like:
typedef std::basic_string<TCHAR> tstring;
What issues if any arise from these sorts of patterns on other systems?
There is no support for a generic (variable-width) chararacter like
TCHARin standard C++. C++ does havewchar_t, but the encoding isn’t guaranteed. C++1x will much improve things once we havechar16_tandchar32_tas well as UTF-{8,16,32} literals.I personally am not a big fan of generic characters because they lead to some nasty problems (like conversion) and, what’s more, if you are using a type (like
TCHAR) that might ever have a maximum width of 8, you might as well code withchar. If you really need that backwards-compatibility, just use UTF-8; it is specifically designed to be a strict superset of ASCII. You may have to use conversion APIs (especially on Windows, which for some bizarre reason is UTF-16), but at least it’ll be consistent.EDIT: To actually answer the original question, other platforms typically have no such construct. You will have to define your TCHAR on that platform, or else use a library that provides one (but as you should no doubt be able to guess, I’m not a big fan of that concept in libraries either).