[英]Converting this code line to C
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: 当我用C编译时,出现错误:
'for' loop initial declarations are only allowed in C99 mode
Im not sure on how to fix this. 我不确定如何解决此问题。
Thank you! 谢谢!
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: 或者如果您的编译器支持它,则根据c99或兼容标准进行编译:
gcc -std=c99 your_code.c
(Note that gnu89/gnu90 is the default (as of 4.8, anyway.)) (请注意,默认值为gnu89 / gnu90(无论如何从4.8开始)。)
只需在循环之前声明int i
。
Try to declare the i variable first. 尝试先声明i变量。
int i;
for ( i = index; i < al->size; ++i )
for ( int i = index; i < al->size; ++i )
needs to become 需要成为
int i;
for (i = index; i < al->size; ++i)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.