Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compile a C project in C99 mode?

Tags:

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=c99 or -std=gnu99 to compile your code 

What does it mean?

How to fix it?

like image 708
mpluse Avatar asked Apr 08 '13 02:04

mpluse


People also ask

What is C99 mode in C?

C99 (previously known as C9X) is an informal name for ISO/IEC 9899:1999, a past version of the C programming language standard.

Does GCC use C99?

C99 is substantially completely supported as of GCC 4.5 (with -std=c99 -pedantic-errors used; -fextended-identifiers also needed to enable extended identifiers before GCC 5), modulo bugs and floating-point issues (mainly but not entirely relating to optional C99 features from Annexes F and G).


1 Answers

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.

like image 173
Blorgbeard Avatar answered Sep 25 '22 22:09

Blorgbeard