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.
c gcc gcc-warning
New contributor
Apoorv Potnis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
|
show 2 more comments
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.
c gcc gcc-warning
New contributor
Apoorv Potnis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
It is valid, but not recommended, for readability sake...
– Matthieu
1 hour ago
3
Unrelated, but the.o
extension is usually used for object files, not for the final executable.
– Federico klez Culloca
1 hour ago
@FedericoklezCulloca Can I ask what is the extension of the final executable? When I remove.o
the file still gets compiled. There is a file namedpractice
in my directory. What is its extension? Its properties show type as "shared library".
– Apoorv Potnis
53 mins ago
2
There's no extension for executables in *nix systems. The filesystem doesn't use that to determine the type of a file. So usually executables just don't have extensions andpractice
is correct. Check your/usr/bin
directory and you'll see that the programs there don't have an extension either.
– Federico klez Culloca
47 mins ago
1
About the fact that its properties say "shared library" is probably because of your desktop environment. If I dofile practice
from the command line I getpractice: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=928002f23b27d5c9bc55a15bf769edfaf3e62c23, not stripped
– Federico klez Culloca
45 mins ago
|
show 2 more comments
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.
c gcc gcc-warning
New contributor
Apoorv Potnis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
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.
c gcc gcc-warning
c gcc gcc-warning
New contributor
Apoorv Potnis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Apoorv Potnis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 32 mins ago
Apoorv Potnis
New contributor
Apoorv Potnis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 1 hour ago
Apoorv PotnisApoorv Potnis
1336
1336
New contributor
Apoorv Potnis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Apoorv Potnis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Apoorv Potnis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
It is valid, but not recommended, for readability sake...
– Matthieu
1 hour ago
3
Unrelated, but the.o
extension is usually used for object files, not for the final executable.
– Federico klez Culloca
1 hour ago
@FedericoklezCulloca Can I ask what is the extension of the final executable? When I remove.o
the file still gets compiled. There is a file namedpractice
in my directory. What is its extension? Its properties show type as "shared library".
– Apoorv Potnis
53 mins ago
2
There's no extension for executables in *nix systems. The filesystem doesn't use that to determine the type of a file. So usually executables just don't have extensions andpractice
is correct. Check your/usr/bin
directory and you'll see that the programs there don't have an extension either.
– Federico klez Culloca
47 mins ago
1
About the fact that its properties say "shared library" is probably because of your desktop environment. If I dofile practice
from the command line I getpractice: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=928002f23b27d5c9bc55a15bf769edfaf3e62c23, not stripped
– Federico klez Culloca
45 mins ago
|
show 2 more comments
It is valid, but not recommended, for readability sake...
– Matthieu
1 hour ago
3
Unrelated, but the.o
extension is usually used for object files, not for the final executable.
– Federico klez Culloca
1 hour ago
@FedericoklezCulloca Can I ask what is the extension of the final executable? When I remove.o
the file still gets compiled. There is a file namedpractice
in my directory. What is its extension? Its properties show type as "shared library".
– Apoorv Potnis
53 mins ago
2
There's no extension for executables in *nix systems. The filesystem doesn't use that to determine the type of a file. So usually executables just don't have extensions andpractice
is correct. Check your/usr/bin
directory and you'll see that the programs there don't have an extension either.
– Federico klez Culloca
47 mins ago
1
About the fact that its properties say "shared library" is probably because of your desktop environment. If I dofile practice
from the command line I getpractice: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=928002f23b27d5c9bc55a15bf769edfaf3e62c23, not stripped
– Federico klez Culloca
45 mins ago
It is valid, but not recommended, for readability sake...
– Matthieu
1 hour ago
It is valid, but not recommended, for readability sake...
– Matthieu
1 hour ago
3
3
Unrelated, but the
.o
extension is usually used for object files, not for the final executable.– Federico klez Culloca
1 hour ago
Unrelated, but the
.o
extension is usually used for object files, not for the final executable.– Federico klez Culloca
1 hour ago
@FedericoklezCulloca Can I ask what is the extension of the final executable? When I remove
.o
the file still gets compiled. There is a file named practice
in my directory. What is its extension? Its properties show type as "shared library".– Apoorv Potnis
53 mins ago
@FedericoklezCulloca Can I ask what is the extension of the final executable? When I remove
.o
the file still gets compiled. There is a file named practice
in my directory. What is its extension? Its properties show type as "shared library".– Apoorv Potnis
53 mins ago
2
2
There's no extension for executables in *nix systems. The filesystem doesn't use that to determine the type of a file. So usually executables just don't have extensions and
practice
is correct. Check your /usr/bin
directory and you'll see that the programs there don't have an extension either.– Federico klez Culloca
47 mins ago
There's no extension for executables in *nix systems. The filesystem doesn't use that to determine the type of a file. So usually executables just don't have extensions and
practice
is correct. Check your /usr/bin
directory and you'll see that the programs there don't have an extension either.– Federico klez Culloca
47 mins ago
1
1
About the fact that its properties say "shared library" is probably because of your desktop environment. If I do
file practice
from the command line I get practice: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=928002f23b27d5c9bc55a15bf769edfaf3e62c23, not stripped
– Federico klez Culloca
45 mins ago
About the fact that its properties say "shared library" is probably because of your desktop environment. If I do
file practice
from the command line I get practice: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=928002f23b27d5c9bc55a15bf769edfaf3e62c23, not stripped
– Federico klez Culloca
45 mins ago
|
show 2 more comments
2 Answers
2
active
oldest
votes
You get a warning with -std=c89 -pedantic
. C99 and later allow other implementation-defined characters in identifiers.
Was editing just when you answered.
– Apoorv Potnis
1 hour ago
Yes. This is the reference: gcc.gnu.org/onlinedocs/gcc-8.2.0/cpp/…
– Apoorv Potnis
51 mins ago
add a comment |
According to this : GCC Documentation
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.
So, $
is valid. I don't know why your book says the opposite.
2
It's not valid C, only on GCC C. Try compiling with -ansi or -std=C11 and the warnings will start appearing.
– Spidey
1 hour ago
@Spidey with-std=c11
no warning appears
– Federico klez Culloca
1 hour ago
1
Try adding -Wall then, to show more warnings.
– Spidey
59 mins ago
@Spidey nope, still no warnings.
– Federico klez Culloca
57 mins ago
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Apoorv Potnis is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55087023%2fwhy-is-gcc-not-showing-a-warning-message-for-using-in-a-variable-name%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You get a warning with -std=c89 -pedantic
. C99 and later allow other implementation-defined characters in identifiers.
Was editing just when you answered.
– Apoorv Potnis
1 hour ago
Yes. This is the reference: gcc.gnu.org/onlinedocs/gcc-8.2.0/cpp/…
– Apoorv Potnis
51 mins ago
add a comment |
You get a warning with -std=c89 -pedantic
. C99 and later allow other implementation-defined characters in identifiers.
Was editing just when you answered.
– Apoorv Potnis
1 hour ago
Yes. This is the reference: gcc.gnu.org/onlinedocs/gcc-8.2.0/cpp/…
– Apoorv Potnis
51 mins ago
add a comment |
You get a warning with -std=c89 -pedantic
. C99 and later allow other implementation-defined characters in identifiers.
You get a warning with -std=c89 -pedantic
. C99 and later allow other implementation-defined characters in identifiers.
edited 43 mins ago
answered 1 hour ago
nwellnhofnwellnhof
23.6k46084
23.6k46084
Was editing just when you answered.
– Apoorv Potnis
1 hour ago
Yes. This is the reference: gcc.gnu.org/onlinedocs/gcc-8.2.0/cpp/…
– Apoorv Potnis
51 mins ago
add a comment |
Was editing just when you answered.
– Apoorv Potnis
1 hour ago
Yes. This is the reference: gcc.gnu.org/onlinedocs/gcc-8.2.0/cpp/…
– Apoorv Potnis
51 mins ago
Was editing just when you answered.
– Apoorv Potnis
1 hour ago
Was editing just when you answered.
– Apoorv Potnis
1 hour ago
Yes. This is the reference: gcc.gnu.org/onlinedocs/gcc-8.2.0/cpp/…
– Apoorv Potnis
51 mins ago
Yes. This is the reference: gcc.gnu.org/onlinedocs/gcc-8.2.0/cpp/…
– Apoorv Potnis
51 mins ago
add a comment |
According to this : GCC Documentation
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.
So, $
is valid. I don't know why your book says the opposite.
2
It's not valid C, only on GCC C. Try compiling with -ansi or -std=C11 and the warnings will start appearing.
– Spidey
1 hour ago
@Spidey with-std=c11
no warning appears
– Federico klez Culloca
1 hour ago
1
Try adding -Wall then, to show more warnings.
– Spidey
59 mins ago
@Spidey nope, still no warnings.
– Federico klez Culloca
57 mins ago
add a comment |
According to this : GCC Documentation
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.
So, $
is valid. I don't know why your book says the opposite.
2
It's not valid C, only on GCC C. Try compiling with -ansi or -std=C11 and the warnings will start appearing.
– Spidey
1 hour ago
@Spidey with-std=c11
no warning appears
– Federico klez Culloca
1 hour ago
1
Try adding -Wall then, to show more warnings.
– Spidey
59 mins ago
@Spidey nope, still no warnings.
– Federico klez Culloca
57 mins ago
add a comment |
According to this : GCC Documentation
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.
So, $
is valid. I don't know why your book says the opposite.
According to this : GCC Documentation
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.
So, $
is valid. I don't know why your book says the opposite.
edited 1 hour ago


Federico klez Culloca
16k134380
16k134380
answered 1 hour ago


Arnaud PeraltaArnaud Peralta
610116
610116
2
It's not valid C, only on GCC C. Try compiling with -ansi or -std=C11 and the warnings will start appearing.
– Spidey
1 hour ago
@Spidey with-std=c11
no warning appears
– Federico klez Culloca
1 hour ago
1
Try adding -Wall then, to show more warnings.
– Spidey
59 mins ago
@Spidey nope, still no warnings.
– Federico klez Culloca
57 mins ago
add a comment |
2
It's not valid C, only on GCC C. Try compiling with -ansi or -std=C11 and the warnings will start appearing.
– Spidey
1 hour ago
@Spidey with-std=c11
no warning appears
– Federico klez Culloca
1 hour ago
1
Try adding -Wall then, to show more warnings.
– Spidey
59 mins ago
@Spidey nope, still no warnings.
– Federico klez Culloca
57 mins ago
2
2
It's not valid C, only on GCC C. Try compiling with -ansi or -std=C11 and the warnings will start appearing.
– Spidey
1 hour ago
It's not valid C, only on GCC C. Try compiling with -ansi or -std=C11 and the warnings will start appearing.
– Spidey
1 hour ago
@Spidey with
-std=c11
no warning appears– Federico klez Culloca
1 hour ago
@Spidey with
-std=c11
no warning appears– Federico klez Culloca
1 hour ago
1
1
Try adding -Wall then, to show more warnings.
– Spidey
59 mins ago
Try adding -Wall then, to show more warnings.
– Spidey
59 mins ago
@Spidey nope, still no warnings.
– Federico klez Culloca
57 mins ago
@Spidey nope, still no warnings.
– Federico klez Culloca
57 mins ago
add a comment |
Apoorv Potnis is a new contributor. Be nice, and check out our Code of Conduct.
Apoorv Potnis is a new contributor. Be nice, and check out our Code of Conduct.
Apoorv Potnis is a new contributor. Be nice, and check out our Code of Conduct.
Apoorv Potnis is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55087023%2fwhy-is-gcc-not-showing-a-warning-message-for-using-in-a-variable-name%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
It is valid, but not recommended, for readability sake...
– Matthieu
1 hour ago
3
Unrelated, but the
.o
extension is usually used for object files, not for the final executable.– Federico klez Culloca
1 hour ago
@FedericoklezCulloca Can I ask what is the extension of the final executable? When I remove
.o
the file still gets compiled. There is a file namedpractice
in my directory. What is its extension? Its properties show type as "shared library".– Apoorv Potnis
53 mins ago
2
There's no extension for executables in *nix systems. The filesystem doesn't use that to determine the type of a file. So usually executables just don't have extensions and
practice
is correct. Check your/usr/bin
directory and you'll see that the programs there don't have an extension either.– Federico klez Culloca
47 mins ago
1
About the fact that its properties say "shared library" is probably because of your desktop environment. If I do
file practice
from the command line I getpractice: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=928002f23b27d5c9bc55a15bf769edfaf3e62c23, not stripped
– Federico klez Culloca
45 mins ago