Short answer: the character set used for wide strings is determined by the wchar_t characteristics known at compile time. Since mbtowc is a library function, this happens when creating libc.
mbtowc reads one character from a string encoded in external encoding and writes it to the wchar_t value, which can represent any character. Similarly, mbstowcs converts an external C encoded string into a simple wchar_t array. From a system point of view, it makes no sense to indicate the "encoding" of the resulting wide character / string, because changing its output encoding in any way violates the use of the resulting wide string as a wchar_t array.
You can describe mbstowcs as creating fixed-width Unicode encodings such as UCS-2 or UCS-4 (more precisely, UTF-16 or UTF-32) if the wide characters correspond to ISO 10646 code points and are wchar_t wide. You can also describe it as little-endian or big-endian depending on your finitude representation of the wchar_t processor. But these are platform properties that you cannot change at run time more than you can change endianness, or ASCII for EBCDIC.
-fwide-exec-charset serves to explicitly indicate to the compiler the encoding corresponding to the internal representation of array-of- wchar_t . This is useful when it is different from the view that the compiler usually generates (because you cross with the compiler or because the compiler was not configured correctly). That's why the manual says that "you will have problems with encodings that don't exactly match in wchar_t ."
source share