Forum : ST7/STM8
Original Post
| Post Information | Post |
|---|---|
|
September 1, 2010 - 2:52pm
|
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
//**
}
...
|
Hi,
Declaring variable u as volatile will forbid any optimization on it:
I hope it helps.
Best Regards,
Vincent
Thank you, Vincent, that is a helpful trick; I forgot I could do that.