这code线转换为C [英] Converting this code line to C

查看:106
本文介绍了这code线转换为C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code线:

I have the following code line:

for ( int i = index; i < al->size; ++i )

//i,index and size are integers.al is an arraylist

当我编译在C,我得到的错误:

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.

感谢您!

推荐答案

无论声明迭代器的循环之外:

Either declare the iterator outside of the loop:

int i;

for (i = index; i < al->size; ++i) {
    do_foo();
}

如果你的编译器支持的话,编译针对C99或兼容标准:

or if your compiler supports it, compile against the c99 or compatible standard:

gcc -std=c99 your_code.c 

(注意gnu89 / gnu90是默认的(如4.8,反正。))

(Note that gnu89/gnu90 is the default (as of 4.8, anyway.))

这篇关于这code线转换为C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆