avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] memcpy() : problem when passing destination pointer


From: Joerg Wunsch
Subject: Re: [avr-gcc-list] memcpy() : problem when passing destination pointer
Date: Thu, 12 Feb 2009 06:59:13 +0100 (MET)

Vincent Trouilliez <address@hidden> wrote:

> I can't find any reference to the volatile keyboard in the
> current avr-libc manual (1.6.2), [...]

Note that volatile is explained in the C standard.

> IIRC it said volatile must be used to keep the compiler from
> optimizing away access to a variable that he thinks might be
> pointless. Like writing a variable that is never read back.

Nope, if the variable is a global one, it will always be written.
Even in the canonical example, it's not that the compiler would
/never/ read the flag variable.  The only thing that happens without
the volatile is that it reads the flag once (because it optimizes the
expensive memory access outside the loop), so it will eventually miss
the update to the variable that happens inside the ISR -- but it
doesn't "throw away" the variable access completely.

So in order to just pass some random value in an array between an ISR
and another thread, it doesn't need to be volatile, as long as the
receiver is not "spin looping" on a value out of that array.

-- 
cheers, J"org               .-.-.   --... ...--   -.. .  DL8DTL

http://www.sax.de/~joerg/                        NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]