optimization in AVR GCC?

Status
Not open for further replies.

evilheart

Member level 3
Joined
Sep 3, 2009
Messages
67
Helped
3
Reputation
8
Reaction score
2
Trophy points
1,288
Location
egypt
Activity points
1,955
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?
 

evilheart said:
it seems it need special way in writing the code or something
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.

Hope this helps.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…