Error: ' for ' loop initial declarations is only allowed in C99 mode

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.