我写了一个递归函数,指向整数的指针作为参数传递。该整数值在函数中递增,但我面临一个奇怪的问题,即在某个值之后它的值永远不会更新。即使我正在检查该地址的值。
下面是代码:--
computeWait(long long int begin, long long int begin2, long long int w,
int* current, int limit)
{
long long int next = 0, arrival = 0;
long long int next1 = 0, service = 0;
long long int serviceTime = 0;
long long int wait = 0;
static long long int Ta = 0;
static long long int Ts = 0;
static long long int W = 0;
while(*current < limit)
{
next = (16807 * begin) % m;
arrival = -200 * log((double)next/m);
next1 = (16807 * begin2) % m;
service = -100 * log(EDRN((double)next1));
wait = max(0, (w + service - arrival));
Ta = Ta + arrival;
Ts = Ts + service;
W = W + wait;
*current = *current + 1;;
computeWait(next, next1, wait, current, limit);
}
printf("\n\nTotal arrival %Ld Total service %Ld Total wait %Ld\n", Ta/limit, Ts/limit, W/limit);
}
int main(int agrc, char* argv[])
{
int num = 0;
int currentValue = 0; // seed number
int end = 1000000;
computeWait(1, 46831694, 0, ¤tValue, end);
}
在 103917 之后,它的值没有得到更新,它给出了内存保护失败。
请让我知道我在哪里做错了,因为修复它似乎很简单。
谢谢,内哈。