2011-04-16 237 views
1

请看看这段代码:while循环变量更新

int page; 
int stop = FALSE; 

while (!stop) { 
    printf("stop0 %i\n", stop); 

    if (physmem[fifo_index % opts.phys_pages] == NULL) { 
     stop = TRUE; 
     page = fifo_index % opts.phys_pages; 
     printf("stop1 %i\n", stop); 

    } else if (physmem[fifo_index % opts.phys_pages]->gc_bit == 0) { 
     physmem[fifo_index % opts.phys_pages]->gc_bit = 1; 
     printf("stop2 %i\n", stop); 

    } else if (physmem[fifo_index % opts.phys_pages]->gc_bit == 1) { 
     stop = TRUE; 
     page = fifo_index % opts.phys_pages; 
     printf("stop3 %i\n", stop); 

    } 
    printf("sto4 %i\n", stop); 

    fifo_index++; 
    printf("stop5 %i\n", stop); 

} 

输出是:

stop0 0 
stop1 1 
stop4 1 
stop5 1 
stop0 0 '<<< I dont understand this part' 
stop1 1 
stop4 1 
stop5 1 
      '<<<< The code exits here!! In the second loop...whyy??' 
+0

此代码是否位于某个外部循环? – Adam 2011-04-16 05:25:50

+1

我注意到你没有真正复制/粘贴输出,因为“sto4”在你的代码中拼写错误,但在你的输出中没有。 – Adam 2011-04-16 05:26:21

+1

你怎么知道它循环了两次?你有可能两次调用这个函数吗? – 2011-04-16 05:27:39

回答

0

你可以把上面的printf声明while和检查,如果你是两次进入循环。

+0

我觉得漂亮stoopid。累:( – moejoe 2011-04-16 06:54:33