How can I embed unicode string constants in a source file?

前端 未结 3 1554
一向
一向 2020-12-09 05:33

I\'m writing some unit tests which are going to verify our handling of various resources that use other character sets apart from the normal latin alphabet: Cyrilic, Hebrew

3条回答
  •  眼角桃花
    2020-12-09 06:22

    You have to tell GCC which encoding your file uses to code those characters into the file.

    Use the option -finput-charset=charset, for example -finput-charset=UTF-8. Then you need to tell it about the encoding used for those string literals at runtime. That will determine the values of the wchar_t items in the strings. You set that encoding using -fwide-exec-charset=charset, for example -fwide-exec-charset=UTF-32. Beware that the size of the encoding (utf-32 needs 32bits, utf-16 needs 16bits) must not exceed the size of wchar_t gcc uses.

    You can adjust that. That option is mainly useful for compiling programs for wine, designed to be compatible with windows. The option is called -fshort-wchar, and will most likely then be 16bits instead of 32bits, which is its usual width for gcc on linux.

    Those options are described in more detail in man gcc, the gcc manpage.

提交回复
热议问题