Reputation: 373
What does __G
signify in C?
I'm using GCC 4.9.
I'm using latest MinGW version.
I'm compiling with -std=gnu11
.
I have the following C (being compiled with GCC as C11) code:
#ifndef __G
#define __G 0
#endif
It compiles fine.
But now, while compiling with the latest MinGW, i get the following:
In file included from ../common/sysbase/sysbase.h:6:0,
from Monitor.c:5:
../common/sysbase/sysbase_chk.h:3:13: error: expected ';', ',' or ')' before numeric constant
#define __G 0
compilation terminated due to -Wfatal-errors.
GCC under MinGW64 seems to be using `__G for something.
I could not find it in any header.
Upvotes: 0
Views: 129
Reputation: 263287
__G
is simply an identifier. I'm not aware of any standard usage of it, but since it starts with two underscores, it's reserved to the implementation for all purposes. The word "implementation" here refers to the C compiler and library, not to any code you write (unless you're implementing part of the compiler or C standard library yourself.)
(The standard says that any identifier starting with two underscores, or with an underscore and an uppercase letter, are reserved for any use; any identifier starting with an underscore is reserved for use with file scope. See section 7.1.3 of the N1570 C standard draft.)
You should not use it in your own code. Doing so causes your program's behavior to be undefined.
The C implementation (either the compiler, the linker, a header, or the library) is permitted to define __G
in any way it likes. Apparently this is what you've run into.
In answer to a question in your comment:
Now, after more than a year compiling codes with those headers, will I have to change aaalll my codes?
Yes, that's exactly what I'm saying. Your usage of __G
has always been incorrect; you just happen not to have run into any visible symptoms until now.
(It's at least conceivable that previous versions of MinGW defined it in some way that didn't cause your code to fail to compile, but that could have cause it to misbehave.)
Upvotes: 4