This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

variable suddenly reset to 0

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

Parents Reply Children
No data