Search code examples
cgccgcc-warning

Why is gcc not showing a warning message for using $ in a variable name?


I'm new to C and am learning C from Programming in C, 4th ed. by Stephen Kochan. On page 29, he writes $ is not a valid character for variable names. He is using the C11 standard.

I wrote the following code

#include <stdio.h>

int main (void)
{
    int a$ = 1;

    printf ("%i", a$);

    return 0;
}

and ran it with the command gcc -std=c11 -pedantic practice.c -o practice.o && ./practice.o. My filename is practice.c.

The output is 1. Shouldn't the compiler give me a warning for using $? Isn't using $ sign for identifiers an extension that GCC provides?

I'm using GCC 8.2.0 in Ubuntu 18.10.

Edit:

Also, doesn't GCC not use the GNU extensions when I use -std=c11? That is what is written in the Appendix of the book (pg. no. 497).

I am getting an warning by using -std=c89 though.


Solution

  • You get a warning with -std=c89 -pedantic. C99 and later allow other implementation-defined characters in identifiers.