i want to know more about each level of optimization in AVR GCC ,
it does reduce the size greatly , but it seems it usually causes bugs , it seems it need special way in writing the code or something ,
can any one gives me a link or a reference giving more details about dealing with optimization levels?
One general rule that stands for all compilers, is to declare all variables that are shared between main and interrupts as volatile. This is the reason for the most of the bugs in an optimized code. Also all variables that writing or reading values to/from the real world (ADC, UART, ports etc), must be also declared as volatile. Read the following article to understand why you must do that. Pay close attention to the example. Volatile variable - Wikipedia, the free encyclopedia
If you are not sure if a variable must be declared as volatile or not, declare it as volatile. The penalty for a volatile variable is that the code that related with this variable will not be optimized so effectively compared with a non volatile variable.