This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Does the keyword volatile work?
- From: Mike Stump <mrs at apple dot com>
- To: "Stephen P. Smith" <ischis2 at cox dot net>
- Cc: gcc at gcc dot gnu dot org
- Date: Mon, 12 May 2003 16:57:31 -0700
- Subject: Re: Does the keyword volatile work?
On Monday, May 12, 2003, at 09:59 AM, Stephen P. Smith wrote:
In the code fragment
Asking for help with code fragments is dangerous. If you know exactly
how to ask the question and the right person reads it, it can work
fine. If you don't, or they don't, it can fail.
There wasn't any sensible code that I could discern to help you with.
Try writing a 10 line program (or at least translation unit) that has
no includes that is cross platform portable and ask us about it.
For example,
volatile int mailbox;
int foo(int i) {
mailbox = i;
}
is such a best. When I compile it, it works fine:
_foo:
lis r2,ha16(_mailbox)
stw r3,lo16(_mailbox)(r2)
blr
as you can see, the variable is immediately fetched and stored.
I can guess all day long at what you really want to do, but every
example I would come up with, would necessarily work:
int foo(int i) {
int mailbox;
(*(volatile *)&mailbox) = i;
}
gives:
_foo:
stw r3,-16(r1)
blr
so, I'm back at asking, what do you really want to do? Is the fetch
volatile, or is the store volatile?