C:编写一个由中断/回调迭代的嵌套循环

nhjlsmyf  于 2023-05-12  发布在  其他
关注(0)|答案(3)|浏览(103)

考虑以下函数:

void callback(){
  for (int i=0; i<100; i++)
    for (int j=0; j<20; j++)
      do_something(i,j);
}

我希望do_something(i,j)被调用,并且i,j像嵌套的for循环一样递增,每次callback()被中断调用时。
我试着用静态变量写这个代码,如下所示:

void callback(){
  static int i=0, j=0;

  do_something(i,j);

  if (j==20)
    if (i==100) // done
    else i++;
  else j++;
}

这不是很可读,特别是考虑到我需要为嵌套多达6层的循环这样做。有什么建议吗?

qni6mghb

qni6mghb1#

你可能想要这样的东西:

void callback(void){
    static int i=0, j=0;

    do_something(i,j);

    ++ j;
    if (j >= 20)
    {
        j = 0;
        ++ i;
        if (i >= 100)
        {
            // That's all folks!
            i = 0;
        }
    }
}

如果在迭代完所有的“循环”之后调用回调函数,会发生什么还不清楚。我把它重新从(0,0)开始。

toe95027

toe950272#

如果你有很多计数器要递增,不要使用单独的变量,使用一个数组来保存它们。然后你可以增加他们的里程表风格。

#include <stdio.h>

void do_something(int *vars, int count) {
    for (int i = 0; i < count; i++) {
        printf("%d ", vars[i]);
    }
    printf("\n");
}

void callback() {
    static int vars[] = {0, 0, 0, 0, 0, 0};
    const int varmax[] = {3, 4, 5, 15, 10, 30};
    const int varcount = sizeof vars / sizeof *vars;

    do_something(vars, varcount);

    // increment each variable. When wrapping around, increment the next one
    for (int i = 0; i < varcount && ++vars[i] >= varmax[i]; i++) {
        vars[i] = 0;
    }
}

int main() {
    for (int i = 0; i < 1000; i++) {
        callback();
    }
}

输出:

0 0 0 0 0 0 
1 0 0 0 0 0 
2 0 0 0 0 0 
0 1 0 0 0 0 
1 1 0 0 0 0 
2 1 0 0 0 0 
0 2 0 0 0 0 
1 2 0 0 0 0 
2 2 0 0 0 0 
0 3 0 0 0 0 
1 3 0 0 0 0 
2 3 0 0 0 0 
0 0 1 0 0 0 
1 0 1 0 0 0 
2 0 1 0 0 0 
0 1 1 0 0 0 
1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0 1 1 0 
2 0 0 1 1 0 
0 1 0 1 1 0 
1 1 0 1 1 0 
2 1 0 1 1 0 
0 2 0 1 1 0 
1 2 0 1 1 0 
2 2 0 1 1 0 
0 3 0 1 1 0 
1 3 0 1 1 0 
2 3 0 1 1 0 
0 0 1 1 1 0 
1 0 1 1 1 0 
2 0 1 1 1 0 
0 1 1 1 1 0 
1 1 1 1 1 0 
2 1 1 1 1 0 
0 2 1 1 1 0 
1 2 1 1 1 0 
2 2 1 1 1 0 
0 3 1 1 1 0 
1 3 1 1 1 0 
2 3 1 1 1 0 
0 0 2 1 1 0 
1 0 2 1 1 0 
2 0 2 1 1 0 
0 1 2 1 1 0 
1 1 2 1 1 0 
2 1 2 1 1 0 
0 2 2 1 1 0 
1 2 2 1 1 0 
2 2 2 1 1 0 
0 3 2 1 1 0 
1 3 2 1 1 0 
2 3 2 1 1 0 
0 0 3 1 1 0 
1 0 3 1 1 0 
2 0 3 1 1 0 
0 1 3 1 1 0
e4eetjau

e4eetjau3#

如果你想让它看起来像嵌套的for循环,可以写嵌套的for循环:

void callback(void)
{
    goto Resume;

    static int i = 0, j = 0;
    for (i = 0; i < 100; i++)
        for (j = 0; j < 20; j++)
        {
            return;
Resume:
            do_something(i, j);
        }

    //  Done, put final code here.
}

相关问题