首页 > 代码库 > error: ‘for’ loop initial declarations are only allowed in C99 mode

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

在gcc中,写了这样几句代码

for(int i=1; i<=2; i++)
{
  if(*e >= T[i])
  {
    *e = T[i];
  }
}

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

这种for循环的写法在gcc中不支持,得现在for循环之前对i进行i定义,然后在使用

如果非得这么写的话在gcc进行编译的时候可以加上如下选项

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

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