Compiler problem, error: ‘for’ loop initial declarations are only allowed in C99 mode

using GCC to compile the code is to report

error: ‘for’ loop initial declarations are only allowed in C99 mode

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

The

error is due to the increment being initialized in GCC directly in the for loop:

  1. for (int I = 0; I< len; I++) {
  2. }

    this syntax is incorrect in GCC, you must first define the I variable:

    1. int I;
    2. for (I = 0; i< len; I++) {
    3. }

      this is because GCC is based on the c89 standard, instead of the C99 standard, you can define the I variable within the for loop:

      gcc src.c -std=c99 -o src

Read More: