C++ syntax uses almost all printable ASCII characters and some of them in several contexts. Only two unused are @ and $ characters. Why they are not used? Are they reserved for some "meta" purpose?

  • 2
    Note that this makes @ useful in documentation where it often stands for “any operator”. – Jan Hudec Jan 14 '15 at 10:20

It is implementation defined (so you should avoid using them if you care about portability).

Some compilers (e.g. GCC) accept $ in identifiers.

BTW, the backquote ` is also unused in C++.

Notice that early definition of C or C++ languages did not require (and where not used) on systems using ASCII. This explains why some ASCII characters remain unused. (Some systems used EBCDIC and had a C compiler).

Read also about the (ugly) trigraphs (they might go away in C++17)

Be aware of UTF-8 (perhaps some compilers accept it as an extension...)

As Jules commented, read also about name mangling.

  • 2
    Good answer. The only relevant point I can think of that you haven't covered is that these characters are often used in name mangling schemes (presumably because they shouldn't show up in legal identifiers therefore there's no need to use an escaping scheme to prevent collisions). – Jules Jan 14 '15 at 10:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.