Are dollar-signs allowed in identifiers in C++03? covers that dollar signs in identifiers are not allowed in C++03. GCC provides it as a C extension and properly gives a diagnostic in C++03 mode. However, in C++11, int $ = 0
will compile without warning.
This answer reasons that $
may be allowed because no diagnostic is required for implementation defined identifiers:
The answer here is "Maybe": According to §2.11, identifiers may consist of digits and identifier-nondigits, starting with one of the latter. identifier-nondigits are the usual
a-z
,A-Z
and underscore, in addition since C++11 they include universal-character-names (e.g.uBEAF
,UC0FFEE32
), and other implementation-defined characters. So it is implementation defined if using$
in an identifier is allowed. VC10 and up supports that, maybe earlier versions, too. It even supports identifiers likeこんばんわ
.But: I wouldn't use them. Make identifiers as readable and portable as possible.
$
is implementation defined and thus not portable.
This language is present in the C++03 standard as well, so I don't find this to be a very convincing argument.
§2.10/2
In addition, some identifiers are reserved for use by C ++ implementations and standard libraries (17.6.4.3.2) and shall not be used otherwise; no diagnostic is required.
What change in the standard allows $
to be used as an identifier name?