如何修复“在 C99 模式之外使用的 for 循环初始声明"?海湾合作委员会错误? [英] How do I fix "for loop initial declaration used outside C99 mode" GCC error?

查看:20
本文介绍了如何修复“在 C99 模式之外使用的 for 循环初始声明"?海湾合作委员会错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试解决3n+1 问题,我有看起来像这样的 for 循环:

I'm trying to solve the 3n+1 problem and I have a for loop that looks like this:

for(int i = low; i <= high; ++i)
        {
                res = runalg(i);
                if (res > highestres)
                {
                        highestres = res;
                }

        }

不幸的是,当我尝试使用 GCC 进行编译时出现此错误:

Unfortunately I'm getting this error when I try to compile with GCC:

3np1.c:15: 错误:'for' 循环初始在 C99 模式之外使用的声明

3np1.c:15: error: 'for' loop initial declaration used outside C99 mode

我不知道什么是 C99 模式.有什么想法吗?

I don't know what C99 mode is. Any ideas?

推荐答案

我会尝试在循环之外声明 i

I'd try to declare i outside of the loop!

祝你成功解决 3n+1 :-)

Good luck on solving 3n+1 :-)

这是一个例子:

#include <stdio.h>

int main() {

   int i;

   /* for loop execution */
   for (i = 10; i < 20; i++) {
       printf("i: %d
", i);
   }   

   return 0;
}

此处阅读有关 C 中 for 循环的更多信息.

Read more on for loops in C here.

这篇关于如何修复“在 C99 模式之外使用的 for 循环初始声明"?海湾合作委员会错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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