I have written one recursive function and pointer to integer is passed as an argument. That integer value is incremented in function, but I am facing a strange issue that after some value its value never get updated. Even I am checking the value at that address.
Below is the code:–
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);
}
After 103917, its value doesnot get updated and it gives memory protection failure.
Please let me know where I am doing something wrong as it seems so trivial to fix it.
Thanks,
Neha.
Well, I did not really try to understand the code, but I saw some big numbers and the word recursion.
So I would guess its a stack overflow because your recursion is too deep?