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

Unwanted optimize

My program works wrong because of c compiler's optimization. If I use "volatile" to declare some varibles and functions, the optimization will be affetced, and perhaps the program works well, but if I changed the program, I would have to add "volatile" to other varibles or functions. I have to try many times to make compiler compile my program "correctly" after change the program.

Is there a way to remove optimization completely? I use
#pragma SAVE
#pragma OPTIMIZE(0)

my_func1()
{
...;
}

#pragma RESTORE

but I know optimize level 0 doesn't mean no optimization, and my program can't be compiled correctly even at optimize level 0, if without "volatile" to most varibles and functions.

I only use P0, P1 and P2, to read and write some IO lines. Compiler is keil c51 v6.12