On Dec 3, 2010, at 9:28 AM, Richard wrote:
In article <4CF88835.4090606 at tx.rr.com>,
Charlie Carothers <csquared3 at tx.rr.com> writes:
I'm afraid I must disagree. What if, for my
own nefarious purposes, I
need the N microseconds of delay achieved via the "spurious" for loop?
Put that code in a compilation unit that is compiled with
optimizations turned off.
Better yet, have the loop call an external (to the compilation unit) function (that does
nothing - ie just returns). The optimizer can't eliminate the loop because it
doesn't know what side effects the function may have. The other way to deal with this
is to declare a variable as a volatile pointer and keep reading it. The optimizer
can't remove the reads (or writes) to a volatile pointer.
Although the best case would be to have a high resolution clock that you keep checking
(but again that would use either an external function or a volatile pointer).
TTFN - Guy