Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
375 views
in Technique[技术] by (71.8m points)

g++ unicode variable name

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 unicode (from which I'm not testing in).

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 hu00F8yde = 10;

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...