问题
I have the following code line:
for ( int i = index; i < al->size; ++i )
//i,index and size are integers.al is an arraylist
When I compile this in C, I get the error:
'for' loop initial declarations are only allowed in C99 mode
Im not sure on how to fix this.
Thank you!
回答1:
Either declare the iterator outside of the loop:
int i;
for (i = index; i < al->size; ++i) {
do_foo();
}
or if your compiler supports it, compile against the c99 or compatible standard:
gcc -std=c99 your_code.c
(Note that gnu89/gnu90 is the default (as of 4.8, anyway.))
回答2:
Just declare int i
before the loop.
回答3:
Try to declare the i variable first.
int i;
for ( i = index; i < al->size; ++i )
回答4:
for ( int i = index; i < al->size; ++i )
needs to become
int i;
for (i = index; i < al->size; ++i)
来源:https://stackoverflow.com/questions/33457768/converting-this-code-line-to-c