Why can you start a variable name with $ in C?

In the C 2018 standard, clause 6.4.2, paragraph 1 allows implementations to allow additional characters in identifiers.

It defines an identifier to be an identifier-nondigit character followed by any number of identifier-nondigit or digit characters. It defines digit to be “0“ to “9”, and it defines the identifier-nondigit characters to be:

  • a nondigit, which is one of underscore, “a” to “z”, or “A” to “Z”,
  • a universal-character-name, or
  • other implementation-defined characters.

Thus, implementations may define other characters that are allowed in identifiers.

The characters included as universal-character-name are those listed in ranges in Annex D of the C standard.

The resource you link to is wrong in several places:

Variable names in C are made up of letters (upper and lower case) and digits.

This is false; identifiers may include underscores and the above universal characters in every conforming implementation and other characters in implementations that permit them.

$ not allowed -- only letters, and _

This is incorrect. The C standard does not require an implementation to allow “$”, but it does not disallow an implementation from allowing it. “$” is allowed by some implementations and not others. It can be said not to be a part of strictly conforming C programs, but it may be a part of conforming C programs.


This answers your question:

In GNU C, you may normally use dollar signs in identifier names. This is because many traditional C implementations allow such identifiers. However, dollar signs in identifiers are not supported on a few target machines, typically because the target assembler does not allow them.


This is allowed in GCC and LLVM because many traditional C implementations allow identifiers like this.

One such reason is that VMS commonly uses these, where a lot of system library routines have names like SYS$SOMETHING.

Here's a link to the GCC docs describing this:

https://gcc.gnu.org/onlinedocs/gcc/Dollar-Signs.html