I am π to find that I cannot use π as a valid identifier with g++ 4.7, even with the -fextended-identifiers
option enabled:
int main(int argc, const char* argv[])
{
const char* π = "I'm very happy";
return 0;
}
main.cpp:3:3: error: stray β\360β in program
main.cpp:3:3: error: stray β\237β in program
main.cpp:3:3: error: stray β\230β in program
main.cpp:3:3: error: stray β\203β in program
After some googling, I discovered that UTF-8 characters are not yet supported in identifiers, but a universal-character-name should work. So I convert my source to:
int main(int argc, const char* argv[])
{
const char* \U0001F603 = "I'm very happy";
return 0;
}
main.cpp:3:15: error: universal character \U0001F603 is not valid in an identifier
So apparently π isn't a valid identifier character. However, the standard specifically allows characters from the range 10000-1FFFD
in Annex E.1 and doesn't disallow it as an initial character in E.2.
My next effort was to see if any other allowed Unicode characters worked - but none that I tried did. Not even the ever important PILE OF POO (π©) character.
So, for the sake of meaningful and descriptive variable names, what gives? Does -fextended-identifiers
do as it advertises or not? Is it only supported in the very latest build? And what kind of support do other compilers have?
universal-character-name
, so whatever advice they give on naming conventions doesn't take into account the importance of using smiley faces as variable names. See §2.11 of ISO/IEC 14882:2011(E). β Cominternstatic const char* xπ = "I'm very happy";
crashes clang 3.1... β Forejudgeclang
supports this since3.3
with no special options butgcc 4.8.1
still doesn't. Related: #26660680 β Fasciation