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.
You can request many specific warnings with options beginning with ' -W ', for example -Wimplicit to request warnings on implicit declarations. Each of these specific warning options also has a negative form beginning ' -Wno- ' to turn off warnings; for example, -Wno-implicit .
You can use the -Werror compiler flag to turn all or some warnings into errors.
gcc -Wall enables all compiler's warning messages. This option should always be used, in order to generate better code.
The "-Werror" compiler flag treats all warnings as build errors. By promoting all warnings to errors, it enforces the developers to ensure such build warnings that may otherwise go unnoticed or only loosely concerned about by developers to now treat it with priority given that it will interrupt the build process.
You get a warning with -std=c89 -pedantic
. C99 and later allow other implementation-defined characters in identifiers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With