0

I have read online and in print (the ANSI C book by Kochan) that one cannot use the dollar sign $ in a variable name when programming in C. Yet, when I created the following code to test variable names as part of exercise 2 in chapter 4 of Kochan's book I am able to compile and run the code.

So, is GCC breaking the rules by allowing $ or have the rules for variable names been changed to allow for the $?

Here is my terminal output:

user@computer# cat Answer-4_2_for_post.c
#include <stdio.h>
int main()
{
  int A$;
  A$ = 1;
  printf ("variable A$ = %i\n",A$);
  return 0;
}
user@computer# gcc ./Answer-4_2_for_post.c -o ./Answer-4_2_for_post
user@computer# ./Answer-4_2_for_post 
variable A$ = 1
user@computer#
2
  • 3
    This question would better fit on StackOverflow. Try to compile it using this command gcc -std=c11 -pedantic-errors -Wall -Wextra ./Answer-4_2_for_post.c -o ./Answer-4_2_for_post I also found this. Jun 24, 2016 at 10:23
  • 2
    someone already asked similar question on SO for c++, but maybe you will find some useful info there too Jun 24, 2016 at 10:25

1 Answer 1

2

Section 6.39 Dollar Signs in Identifier Names of the GCC manual states:

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.

Not the answer you're looking for? Browse other questions tagged .