Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is the best practice for creating libraries that support both Unicode and ASCII in C++?
    primarykey
    data
    text
    <p>I'm working on writing some libraries that will be used both internally and by customers and was wondering what the best method of supporting both Unicode and ASCII. It looks like Microsoft (in the MFC Libraries) writes both the Unicode and ASCII classes and does something similar to this in the header files using macros:</p> <pre><code>#ifdef _UNICODE #define CString CStringW #else #define CString CStringA #endif </code></pre> <p>While I'm not a huge fan of macros, it does the job. If I'm writing libraries using the STL, does it make sense to write headers that contain things like this:</p> <pre><code>#ifdef _UNICODE #define GetLastErrorString GetLastErrorStringW #else #define GetLastErrorString GetLastErrorStringA #endif std::string GetLastErrorStringA(); std::wstring GetLastErrorStringW(); </code></pre> <p>Or should I just release separate libraries, one for ASCII and one for Unicode? </p> <p>Just wondering what people think is the best thing to do in this situation.</p> <p>UPDATE: Addressing some comments and questions:</p> <ul> <li>These will be C++ class libraries.</li> <li>I believe I will need to use UTF-16 encoding as I would like to support Asian character sets.</li> <li>My reasons for implementing Unicode are twofold: 1) All new SDKs support Unicode and I'm not confident that future SDKs or third party libraries will be supporting separate ASCII versions in the future. 2) While we will not be completely internationalizing our application, it would be nice if we could handle user input (like names) and files loading from paths that contain Asian characters.</li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload