For example, write the following procedure:
for (int i = 0; i < n; ++i)
Do_something ();
Then it compiles with GCC and will report the error of ' for ' loop initial declarations is only allowed in C99 mode.
The reason is that variables are declared in the loop condition and are only supported in the C99 standard, which is not supported by the C90 standard.
So change to:
int i;
for (i = 0; i < n; ++i)
Do_something ();
This will allow the compilation to pass.
To compile the pass without changing the code, use:
GCC src.c-std=c99-o src
Error at this time:
~/c_test$ cc-std=gnu99 SRC.C
Src.c:9:1:warning:return type defaults to ' Int. ' [enabled by default]
Main () {
^
Because C99 must be
int main () {
return 0;
}
The format
Under Linux, use Vim to compile the. c File options:
1. No option to compile links
Usage: #gcc src.c
Role: Pre-SRC.C, assemble, compile, and link the executable file. The output file is not specified here, and the default output is a.out.
2. Option-O
Usage: #gcc src.c-o src
Role: Pre-SRC.C, assemble, compile, and link the executable file src. The-o option is used to specify the file name of the output file.
3. Option-E
Usage: #gcc-e src.c-o src.i
Function: The SRC.C preprocessing output src.i file.
4. Option-S
Usage: #gcc-S SRC.I
Function: src.i the preprocessed output file into a Src.s file.
5. Option-C
Usage: #gcc-C Src.s
Function: Compiles output file Src.s compiled output SRC.O file.
6. No option link
Usage: #gcc test.o-o src
Function: Link the compiled output file SRC.O to the final executable src.
7. Option-O
Usage: #gcc-o1 src.c-o src
Role: Compile the program using the Compile Optimization level 1. The higher the level, the better the optimization effect, but the longer the compilation time.
Error: ' for ' loop initial declarations is only allowed in C99 mode