Hi ti all, i am developing a device with keil MDK arm and i encountred with an strange behavior, look at below code:
uint16_t var = 1; uint16_t* ptr = 0; for(var = 1; var < 100; var++) { do_some_thing(); //this function always reset the var to 0 }
in above code after calling the do_some_thing(), var is resetting to 0, but in below code this did not happen:
uint16_t var = 1; uint16_t* ptr = 0; ptr = &var; for(var = 1; var < 100; var++) { do_some_thing(); //this function always reset the var to 0 }
i can not understand reason of this behavior, i think that it may be a problem with keil code optimization but anyway, can any one explain me that why this behavior occur ??
thanks
Most likely an issue with the stack, heap and statics colliding. Make sure your stack allocation is sufficient to accommodate all your local/auto variables for however deep your call tree is in these other functions.