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, int $ = 0 will compile without warning.

This is because $ can not be allowed because no diagnostics is required for implementation define identifiers:

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 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

But: I will not use them. Make identifiers as readable and portable as possible. The implementation of $ is defined and thus is not portable.

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 $ to be used as an identifier name?

This implementation is defined behavior, not included in the $ grammar for the identifier There are rules for identifier names in C ++11 :

  1. this can not start with a number
  2. may be composed of letters , Numbers

    Implementation-Defined Characters Chimes Extensions including several compilers Is supported and apparently as no Has been fixed.

    Grammar section 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 [...]   

    If we use this code by using clang -Pink-Errors flag will not compile it:

      int $ = 0   

    and generates the following error:

      Error: '$' in the identifier [-wire, -wadler-in-identifier-extension] int $ = 0; ^    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -