arrays - I have a for loop that refuses to stay within the defined limits. The limits have been verified (by printing) during runtime -


i inserting snippet of code causing problem. please focus on uncommented code, actual code. commented out code there me debug. apologies poor readability, decided let comments stay, in case had doubt how arrived @ diagnosis of problem.

void backprop(double back_prop_err, double x[])// x complete output of input layer neurons.     {         //j++;         //printf("\na"); printf("\nj=%d",j);         error = out*(1-out)*back_prop_err;         printf("\nb:%20.18f",error);         //if(j==8)         //{         //      printf("\nstart= %d, stop= %d",start, stop);         //      temp=1;         //}         for(int i=start; i<= stop; i++)         {         //  if(i==24)         //      break;         //  if(temp==1)         //  {         //      printf("\nstart= %d , stop= %d", start, stop); //temp=0;         //  }             //j++;             //printf("\nc");             del_w[i] = c*error*x[i];             printf("\ndel_w[%d]=%20.18f",i,del_w[i]);         }     } 

please ignore commented out sections. there display stuff on screen, debug code.

the problem:

there 3 classes, let's call them a, b , c. has 24 objects, stored array. b has 10 objects, again in array , c has 1 object.

the above code b class.

for class b's object[7], value of start , stop (see above code) 0 , 23, respectively. have verified same during runtime using commented out pieces of code see above.

yet, when backprop function called, @ particular loop, infinite loop entered. value of keeps increasing without bound till devc++ crashes. commented out if(i==24) put there prevent that.

this happens class b's object[7]... not previous 7 objects (object[0]...object[6]). them, particular loop starts , stops per set "start" , "stop" variables. important objects, "stop" small number (like 6 or 12 max)?

class b's object[8] , object[9] have stop = 23, leads me suspect face same problem.

the question: why happening? start , stop variables set. why isn't loop staying within limits?

i have tried keep concise possible. thank efforts @ reading wall of question.

edit: start , stop private variables of class b (of which, above function public function). set respective values using public function, call main.

j embarrassing. it's global static integer, set 0. reason did count when class b's object[7] accessing backprop function. j gets incremented each time backprop called, , it's static global, acts counter can count till object[7].

as per oak's suggestion, putting link code here: http://pastebin.com/ftxbgs2y

yeah, efforts on learn devc++ debugger. :p

i pretty sure don't have problems dimensions of x. matter again though.

my bet modifying unintentionally when writing elements del_w[]: perhaps number of elements in array not large enough doing.

i because , del_w close each other on stack don't know sure because don't know how allocated memory del_w.

check bounds of arrays carefully, remembering 0 based.

it not funny in loop; can trust compiler!

but use debugger though or you'll waste time.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -