c++ - Does C++11 allow dollar signs in identifiers? -
It includes that the dollar sign is not allowed in the identifier in C ++ 03. GCC provides a diagnosis in C ++ 03 mode and provides properly. However, in C ++ 11, This is because The answer to this "Maybe" : According to § 2.1.1 , in the identifier digits and identifiers- nondigits , in the latter Starting with one. Identifier- nondigits general But: I will not use them. Make identifiers as readable and portable as possible. The implementation of This language also exists in the C ++ 03 standard, so I do not think there is a very logical reasoning. §2.10 / 2 Additionally, some identifiers are reserved for use by C ++ implementations and standard libraries (17.6.4.3.2) and otherwise not used Will be done; No diagnostic is necessary. What changes in the standard allow This implementation is defined behavior, not included in the Implementation-Defined Characters Grammar section If we use this code by using and generates the following error: int $ = 0 will compile without warning.
$ can not be allowed because no diagnostics is required for implementation define identifiers:
az ,
AZ and underscore, besides C ++ 11 they include universal character names (e.g.
\ uBEAF ,
\ UC0FFEE32 ), and other implementation-defined characters . Therefore it is being defined that the permission to use
$ in any identifier supports VC10 and above, maybe even the earlier version, too. Also
one a ???? A single
$ is defined and thus is not portable.
$ to be used as an identifier name?
$ grammar for the identifier There are rules for identifier names in C ++11 :
Chimes Extensions including several compilers Is supported and apparently as no Has been fixed.
2.11 Indentifier , I did
& lt; - :
Identifier: identifier- nondigit & lt; Added additional notes starting from - Only a non-digital identifier identifier - nondigit & lt; - The identifier after the next two rules allows for the number & lt; - Identification of characters in two identifiers- nondigit: nondigit & lt; - az, AZ and _ universal-character-name Other implementation-defining characters [...]
clang
int $ = 0
Error: '$' in the identifier [-wire, -wadler-in-identifier-extension] int $ = 0; ^
Comments
Post a Comment