Can C++ variables in cpp file defined as Special Symbols β

前端 未结 3 456
太阳男子
太阳男子 2021-01-21 14:11

Can we define the variable in c++/ c using special characters such as;
double ε,µ,β,ϰ;

If yes, how can this be achieved?

3条回答
  •  难免孤独
    2021-01-21 14:56

    As per the working draft of CPP standard (N4713),

    5.10 Identifiers [lex.name]
    ...
    An identifier is an arbitrarily long sequence of letters and digits. Each universal-character-name in an identifier shall designate a character whose encoding in ISO 10646 falls into one of the ranges specified in Table 2. The initial element shall not be a universal-character-name designating a character whose encoding falls into one of the ranges specified in Table 3.

    And when we look at table 3:

    Table 3 — Ranges of characters disallowed initially (combining characters)

    0300-036F 1DC0-1DFF 20D0-20FF FE20-FE2F
    

    The symbols you have mentioned are the Greek Alphabet which ranges from U+0370 to U+03FF and the extended Greek set ranges from U+1F0x to U+1FFx as per wikipedia. Both these ranges are allowed as the initial element of an identifier.

    Note that not all compilers provide support for this.

    GCC 8.2 with -std=c++17 option fails to compile.
    However, Clang 7.0 with -std=c++17 option compiles.

    Live Demo for both GCC and Clang

提交回复
热议问题