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:
- for (int I = 0; I< len; I++) {
- }
this syntax is incorrect in GCC, you must first define the I variable:
- int I;
- for (I = 0; i< len; I++) {
- }
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