Is it possible to switch off optimization of a specific function? A friend of mine has the problem that the gcc optimization makes some (unknown to me) µ-controller-code not
You could put the function in a separate file and compile that file without optimization but the better solution would be to figure out what is wrong with the code and fix it.
One of the most common bugs that appears when optimization is enabled with gcc is with strict aliasing. Make sure all warnings are enabled and see if you get any warnings that might help you figure out what the problem is. If you can't figure it out, try to reduce the problem to a small, complete program and post it here.