overlap problem

in C51, if I use overlap optimize, my project have problem.( routine R1 changed routine R2's auto variable). if I do not use overlap optimize. the problem gone. Is this Keil's problem? I guess so.
How dose Keil do overlap optimize?

Parents
  • If I understand correctly what you have written, you have two functions (R1 and R2) that both have automatic variables. The optimiser is allocating the same (or overlapping) addresses to the automatic variables of both funtions - which is exactly what it is supposed to do.

    Within a function, your software should not make any assumptions about the value of an automatic variable when the function is started.

    If you want a variable to have a specific value when a function starts, you can define it as automatic but include an initialiser value (or assign a value before you start to use the variable).

    If you want a variable to have a value that persists between calls to a function, you must define the variable a static.

Reply
  • If I understand correctly what you have written, you have two functions (R1 and R2) that both have automatic variables. The optimiser is allocating the same (or overlapping) addresses to the automatic variables of both funtions - which is exactly what it is supposed to do.

    Within a function, your software should not make any assumptions about the value of an automatic variable when the function is started.

    If you want a variable to have a specific value when a function starts, you can define it as automatic but include an initialiser value (or assign a value before you start to use the variable).

    If you want a variable to have a value that persists between calls to a function, you must define the variable a static.

Children
More questions in this forum