g++ unicode variable name

后端 未结 2 611
旧时难觅i
旧时难觅i 2020-12-06 12:29

I am trying to use unicode variable names in g++.

It does not appear to work.

Does g++ not support unicode variable names, ... or is there some subset of uni

2条回答
  •  天命终不由人
    2020-12-06 12:58

    A one-line patch to the cpp preprocessor allows UTF-8 input. Details for gcc are given at

    https://www.raspberrypi.org/forums/viewtopic.php?p=802657

    however, since the preprocessor is shared, the same patch should work for g++ as well. In particular, the patch needed, as of gcc-5.2 is

    diff -cNr gcc-5.2.0/libcpp/charset.c gcc-5.2.0-ejo/libcpp/charset.c
    *** gcc-5.2.0/libcpp/charset.c  Mon Jan  5 04:33:28 2015
    --- gcc-5.2.0-ejo/libcpp/charset.c  Wed Aug 12 14:34:23 2015
    ***************
    *** 1711,1717 ****
        struct _cpp_strbuf to;
        unsigned char *buffer;
    
    !   input_cset = init_iconv_desc (pfile, SOURCE_CHARSET, input_charset);
        if (input_cset.func == convert_no_conversion)
          {
            to.text = input;
    --- 1711,1717 ----
        struct _cpp_strbuf to;
        unsigned char *buffer;
    
    !   input_cset = init_iconv_desc (pfile, "C99", input_charset);
        if (input_cset.func == convert_no_conversion)
          {
            to.text = input;
    

    Note that for the above patch to work, a recent version of iconv needs to be installed that supports C99 conversions. Type iconv --list to verify this, otherwise, you can install a new version of iconv along with gcc as described in the link above. Change the configure command to

    $ ../gcc-5.2.0/configure -v --disable-multilib \
        --with-libiconv-prefix=/usr/local/gcc-5.2 \
        --prefix=/usr/local/gcc-5.2 \
        --enable-languages="c,c++"
    

    if you are building for x86 and want to include the c++ compiler as well.

提交回复
热议问题