Search code examples
c++windowsgcccygwin

porting std::wstring to gcc cygwin


I am tryong to port a project written in Visual Studio 2010 from a Microsoft compiler to gcc Cygwin. My question is does gcc Cygwin or gcc support std::wstring ? Is there a work around for that ?


Solution

  • Yes. It supports, But not easy.

    To support wstring, your platform needs to support a whole bunch of wchar_t functionality. q.v. Standard C++ IOStreams and Locales by Langer and Kreft.

    It's really not enough to say "Hey, we've got wchar_t, and wchar_t character traits, so we can turn on std::wstring." The platform also needs to provide support for the C++ wide character I/O: wistream, wostream, facet, cvt, locale. And that's where things become problematic.

    For Cygwin on Windows, the platform is Cygwin (and its amazingly cool POSIX API layer) moreso than the WinAPI.

    ASIDE: I'm not sure what the MinGW situation is, but since MinGW uses WinAPI directly rather than having a more Unix-like POSIX API as the approach, MinGW may not be in this Cygwin situation.

    Windows does support that functionality, but it appears that no one has gone through the considerable effort of plumbing up Cygwin to use those facilities. (Those are the FooW routines, rather than the FooA routines, in the WinAPI. And there is a lot of work to get the locale magic to work correctly.)

    Also, Windows uses a wchar_t of 2 bytes. (Previous UCS-2, from the Unicode 1.0 era. Now with Vista and Win7, it's UTF-16.) It would be a bit retro to have Cygwin use a 2 byte wchar_t, rather than a 4 byte wchar_t. That just makes everything a little more difficult.

    For further details, go to the gcc.gnu.org/ml/gcc-help: