How to compile a C project in C99 mode?

后端 未结 4 2050
隐瞒了意图╮
隐瞒了意图╮ 2020-12-14 17:03

I got the following error message while compiling the C code:

error: \'for\' loop initial declarations are only allowed in C99 mode
note: use option -std=c9         


        
4条回答
  •  粉色の甜心
    2020-12-14 17:57

    You have done this:

    for (int i=0;i<10;i++) {
    

    And you need to change it to this:

    int i;
    for (i=0;i<10;i++) {
    

    Or, as the error says,

    use option -std=c99 or -std=gnu99 to compile your code.

    Update copied from Ryan Fox's answer:

    gcc -std=c99 foo.c -o foo
    

    Or, if you're using a standard makefile, add it to the CFLAGS variable.

提交回复
热议问题