Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I create a variable name with non-ASCII characters in C++?

Tags:

c++

ascii

I have been writing in C++ since 2010.

I’ve just accidentally inputted the “й“ letter in my code, hovered the mouse on it to remove it, and noticed that Visual Studio just says there is no variable “й“.

I wrote int й = 1; and it just compiled!

What did I miss?


It bet it’s probably features of C++11, C++14 or something like this.

like image 706
Artur Avatar asked Nov 01 '25 14:11

Artur


1 Answers

Here's what The Standard says ([lex.phases]):

Physical source file characters are mapped, in an implementation-defined manner, to the basic source character set (introducing new-line characters for end-of-line indicators) if necessary. The set of physical source file characters accepted is implementation-defined.

So your particular implementation supports that, but it's not guaranteed to be portable to any other implementation.

like image 63
molbdnilo Avatar answered Nov 04 '25 07:11

molbdnilo