Unicode Identifiers and Source Code in C++11?

后端 未结 5 1202
难免孤独
难免孤独 2020-11-30 08:48

I find in the new C++ Standard

2.11 Identifiers                  [lex.name]
identifier:
    identifier-nondigit
    identifier identifier-nondigit
    identi         


        
5条回答
  •  余生分开走
    2020-11-30 09:46

    I suggest using clang++ instead of g++. Clang is designed to be highly compatible with GCC (wikipedia-source), so you can most likely just substitute that command.

    I wanted to use Greek symbols in my source code. If code readability is the goal, then it seems reasonable to use (for example) α over alpha. Especially when used in larger mathematical formulas, they can be read more easily in the source code.

    To achieve this, this is a minimal working example:

    > cat /tmp/test.cpp
    #include 
    
    int main()
    {
        int α = 10;
        std::cout << "α = " << α << std::endl;
        return 0;
    }
    > clang++ /tmp/test.cpp -o /tmp/test
    > /tmp/test 
    α = 10
    

提交回复
热议问题