分段故障11时循环,但似乎没有索引越界



我很难理解为什么我的c++代码会导致

分段故障:11

我已经发现错误发生在哪一行,但我仍然不知道问题出在哪里。

double time_MC_loop[]={0.0, 0.0};
while(order_loop<=order-1 and T()<time_MC)
{
order_loop+=1;
if (order_loop!=order)
{
time_MC_loop[1]+=time_MC*pow(3.0,(double)order_loop-order-1);
time_MC_loop[0]=time_MC*pow(3.0,(double)order_loop-order-1);
}
else
{
time_MC_loop[0]=-time_MC_loop[1]+time_MC;
time_MC_loop[1]=time_MC;
}

//here I'm skipping parts of the code where I don't use either T() or time_MC_loop

bool still_time=T()<time_MC_loop[1];
cout<<still_time;

//when I write "exit(1);" here, I don't get a segmentation fault, 
//and the program prints the expected value of the boolean still_time

while(still_time)
{
exit(1);
// However, I get a segmentation fault here, so it seems the bug occurs in the while test.
//...
}

这里T()是一个计时器,它是在我的一位同事编写的库中定义的。它返回一个双精度,表示程序从命令T.ini()到命令T.fin()运行的时间。我已经用过好几次了,从来没有引起过这样的问题,所以我不认为它会引起问题。

感谢您抽出时间!

我发现了错误:在上面代码的第一个while循环中,分段错误发生在一个完全无关的变量上,但不知何故,它没有在这一行打印错误。