David Brown wrote:

>This is a mistake many people make when they are new to embedded
>development, or new to using an optomising C compiler for embedded
>development.  The code snippet "int x = 1; while (x) ; " tells the >compiler
>to enter an infinite loop.  You've already told the compiler what value >"x"
>has - why should it bother re-reading it all the time?  That's what
>optomisation is for - being smart and saving the processor some effort.
>What you need to do is declare your variable to be "volatile" - that >tells
>the compiler the you really do want it to read the memory each loop.

I know this is in the documentation, and there is a workaround, but I
for one would be glad to see the back of this. I've used over a dozen C
compilers for embedded work over the years, and this is the only one
that does this optimisation, after all, short informal delays are the
bread and ripping of embedded work.

It leaves me worried about what else the compiler might be optimising
out. I've always thought that, as engineers, we are grown up enough to
be in charge of the process, not it in charge of us.

Paul Burke

Reply via email to