error: 'for' loop initial declarations are only allowed in C99 mode,declarationsc99
error: 'for' loop initial declarations are only allowed in C99 mode
使用gcc編譯代碼是報出
error: 'for' loop initial declarations are only allowed in C99 mode
note: use option -std=c99 or -std=gnu99 to compile your code
錯誤,這是因為在gcc中直接在for迴圈中初始化了增量:
[cpp] view plaincopy
- for(int i=0; i<len; i++) {
- }
這文法在gcc中是錯誤的,必須先先定義i變數:
[cpp] view plaincopy
- int i;
- for(i=0;i<len;i++){
-
- }
這是因為gcc基於c89標準,換成C99標準就可以在for迴圈內定義i變數了:
gcc src.c -std=c99 -o src
c語言有一個錯誤
#include <stdio.h>
int main (void)
{
long sum=0;
int count,i;
printf("\nEnter the number of integers you want to sum:");
scanf("%d",&count);
for( i=1;i<count||i==count;i++)
/* [Error] 'for' loop initial declarations are only allowed in C99 mode 我估計意思是在for()中定義變數,只能在C99標準裡*/
sum +=i;
printf("\nTotal of the first %d number is %Ld\n",count,sum);
return 0;
}
c 語言程式錯誤 (找錯誤) 程式如下 #include<stdioh> #include<stdlibh> #define TRUE 1 #define FALS
你代碼貼錯了吧,定義的是LISE_INIT_SIZE 後面用的是LIST_INIT_SIZE,怎麼沒看到報LIST_INIT_SIZE未定義的錯誤