g++ unicode variable name

后端 未结 2 613
旧时难觅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 13:00

    You have to specify the -fextended-identifiers flag when compiling, you also have to use \uXXXX or \uXXXXXXXX for unicode(atleast in gcc it's unicode)

    Identifiers (variable/class names etc) in g++ can't be of utf-8/utf-16 or whatever encoding, they have to be:

    identifier:
      nondigit
      identifier nondigit
      identifier digit
    

    a nondigit is

    nondigit: one of
      universalcharactername
      _ a b c d e f g h i j k l m n o p q r s t u v w x y z
      A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
    

    and a universalcharactername is

    universalcharactername:
      \UXXXXXXXX
      \uXXXX
    

    Thus, if you save your source file as UTF-8, you cannot have a variable like e.g.:

    int høyde = 10;
    

    it had to be written like:

    int h\u00F8yde = 10;
    

    (which imo would beat the whole purpose - so just stick with a-z)

提交回复
热议问题