Topic : Selectively disable optimizer?

Forum : ST7/STM8

Original Post
Post Information Post
September 1, 2010 - 2:52pm
Guest

Hi,

I want to keep optimization enabled but force a certain section of code not to be removed/changed during optimization. For example, when debugging sometimes it's nice to check preprocessor definitions by assigning to a temp variable, but I don't do anything with that variable so it would get optimized out. Is there a way to do something like this?

#define X (12*34)      // Would be 408
#define Y ((X-56)/78)   // Would be 4
void init()
{
   unsigned int u;      // temporary local variable for debugging
   ...
   //** Don't optimize this section!!
   u = X;            // Set breakpoint here
   u = Y;            // Check me
   //**
}
...
Replies
Post Information Post
+1
0
-1
September 1, 2010 - 3:43pm
Raisonance Support Team

Hi,

Declaring variable u as volatile will forbid any optimization on it:

volatile unsigned int u;      // temporary local variable for debugging

I hope it helps.

Best Regards,

Vincent

+1
0
-1
September 1, 2010 - 4:59pm
Guest

Thank you, Vincent, that is a helpful trick; I forgot I could do that.