Preprocessor C in GCC treated variable name linux as constant 1.
//test.c:
#include <stdio.h>
int main(void)
{
int linux = 5;
return 0;
}
Looking at the result of pretreating this with gcc-E test.c
,
int main(void)
{
int 1 = 5;
return 0;
}
This is how it's done An error occurred when running. I don't think linux is defined in what?
linux c gcc c-preprocessor
Before the ANSI, long ago, long time ago,
Predefined symbols such as unix
or vax
have been used to specify "on which system this program is being compiled on."
This was before the standard was set, so the system was heavily influenced.
Usually, these macros were set up by the compiler, not by the library header
Because there is no standard, there is no fixed identifier or reservation word, so programmers will not use it on their own.With the same mindset, he made names like unix
however he wanted.
After that, in 1989, the ANSI C standard was created, and since then, the names used by programmers and compilers will not overlap by restricting the creation of symbols at will. For example, if you look at a standard library, you have the macro name beginning with two underscores (_), or an uppercase letter followed by an underscores.
So, in a compiler that defines unix
or linux
without following the standard,
Programmers who follow the standard think that normal code (such as intlinux = 5
) cannot be compiled.
The default setting for gcc is 'Not following standard', so you need to give a separate option.
gcc -std=c90 -pedantic ... #-std=c89 or -ansi may be used
gcc -std=c99 -pedantic
gcc -std=c11 -pedantic
© 2024 OneMinuteCode. All rights reserved.