How to compile a C project in C99 mode?

后端 未结 4 2055
隐瞒了意图╮
隐瞒了意图╮ 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:44

    The other answers give you a work around to deal with GCC's default mode. If you'd like to use C99, (which I do recommend in general) then you have to add that compiler flag:

    gcc -std=c99 foo.c -o foo
    

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

提交回复
热议问题