将此代码行转换为 C [英] Converting this code line to C

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

问题描述

我有以下代码行:

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.))

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

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