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

Memory coruption when compiler optimization is on

Working with a Freescale Kinetis K60. When file optimization is set at level 1. Optimize for time is on. Cross-module optimization is off. We see a RAM variable that gets corupted. This variable is passed as an argument to a function. When the function returns the parameter has changed unexpectedly. Please note this parameter is not a pointer. This does not happen when optimization is off. Here is the code:

    AoVal = (uint16_t) par1;
    if (LimitAoSet(Console, AoVal)) {         // AoVal is not changed here
      Ux_putline(Console, "AO1 set ");
      Ux_putdec2ctz(Console, 2, (int)AoVal);  // AoVal gets corrupted here
      SetAo1(AoVal); }

Why does this happen?

Parents Reply Children