On 2006-07-03, Roberto Padovani <[email protected]> wrote:
> Here's what is dangerous with irq enabled:
>
> two = P6IN + P6IN; // or any other way in which you write directly to "two"
>
> beacuse you inevitably get 2 instructions that sequentially write at
> the memory address of "two":
If you only want "two" written to once, then declare it volatile.
> if an interrupt happens between, it's a mess..... I can't see
> what you mean with atomicity.
>
>>The compiler does not know or care about interrupt functions -
>>it assumes that it has full control of "two" while generating
>>code, and can do what it likes with it.
>
> it's true: YOU have to take care of writing C code correctly so that
> the compiler won't do too much of what it likes
>
> This is safer:
>
> tmp = P6IN + P6IN; // or any other way that I would better like
> two = tmp;
No, it isn't. It generates exactly the same code as
two = P6IN + P6IN;
Unless you declare "two" as volatile, the compiler is free to
write to "two" twice.
> because this is what atomic write to a global variable means.
We know what "atomic write" means.
--
Grant Edwards grante Yow! I'm not an
at Iranian!! I voted for
visi.com Dianne Feinstein!!