This is really strange. This program was working fine on another computer, but when I try it on this one it runs forever. Also it is a for loop, which adds even more to my confusion. SIZE_OF_DATA is a preprocessor variable, which I think might be causing the problem.. But I don’t know. When I add a printf, it shows only one iteration of the outside loop and is looping infinitely in the inner loop. I have no idea why.
for(i=0; i<size; i++){
for(j=0;j<SIZE_OF_DATA; j++){
aArray[i*SIZE_OF_DATA + j] = aPointer[i]->b[j];
cArray[i*SIZE_OF_DATA + j] = 0;
dArray[i*SIZE_OF_DATA + j] = i*SIZE_OF_DATA + j;
if (i==0)
eArray[j] = 0;
}
}
I’m worried that I somehow destroyed my program… But I have barely done anything but add comments!
This:
looks like you might be writing outside the array (
cArrayanddArraytoo) in the last iteration. Are you sure you’re getting a correct index into the array? If not, through the wonders of undefined behavior, you are probably writing to memory that belongs to other variables, includingiandj, which could make this loop go on forever.Buggy programs with undefined behavior behave very… undefined. Though without seeing more code, no one can be sure.