Content originally posted in LPCWare by bladerunner on Sun Feb 28 05:21:05 MST 2010
Quote: CodeRedSupport
No - I meant that the compiler will optimise out the incrementing of your local variable - as it can see that the code does not make any other use of the variable.
The while loop itself will remain - encoded as a branch to self - ie a branch to the location of the branch instruction itself.
If you want to keep the code that increments the variable, then make the variable "volatile". This instructs the compiler that "external factors" may access the variable and will hence prevent the compiler removing the code that increments it within your while(1) loop.
If you look at the main.c that is created by the LPCXpresso Project Wizard, this is exactly what the code this contains does.
Regards,
CodeRedSupport
Yes, turn off the optimization or use the volatile qualifier. Compiler optimization and embedded controllers are uneasy bedfellows :)