C: Difference between revisions

992 bytes added ,  17 years ago
no edit summary
[unchecked revision][unchecked revision]
No edit summary
No edit summary
Line 25:
 
[[Interrupt Service Routines]] (ISRs) also require some special handling, because they are called directly by the CPU, not by the C environment.
 
== Things you should know about optimizations ==
 
At some point you might want to compile your code with optimizations enabled. This however can lead to unpredictable results if your C code wasn't written properly. You might end up wasting days or weeks trying to find out why your code works flawlessly without optimizations, but as soon as you compiled it with optimizations it just doesn't. Operating systems are usually multi-threaded environments these days, however the optimizer of compilers generally assume that algorithms and memory changes are single-threaded and so only visible to one instance. So if the optimizer determines that your code does something that is redundant and could be optimized away, it might remove code or change it's logic any way it wants. These are legit changes to the code, but in some instance it's not what you want and it will simply break it. To prevent such things from happening, use the [[volatile (keyword)|volatile]] keyword where neccessary.
 
[[Category:Languages]]
Anonymous user