[Top][All Lists]

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

Re: [avr-gcc-list] volatile...

From: Dave Hansen
Subject: Re: [avr-gcc-list] volatile...
Date: Fri, 15 Dec 2006 14:44:33 -0500

From: Paulo Marques <address@hidden>

Dave Hansen wrote:


You've opened some new cans of worms here, but I'll only make one small comment

I was afraid of that (the cans of worms, not your comment) ;)

Thanks for noticing the implied smiley. Looking at what I wrote, I'm not sure it has the tone that was intended...


static uint16_t atomic_read_16(uint16_t *ptr)
    uint16_t ret;

    ret = (volatile)(*ptr);

Your cast to volatile here is not only unnecessary, it's wrong.


But you're actually wrong about the volatile not being needed. Because the "sei" instruction doesn't claim anything about memory clobbers, without volatile the compiler would be free to re-order instructions and do the "sei" before the assignment.

Ouch. I would have thought the "volatile" int the sei macro would have taken care of this.

This is no theoretical scenario. Just search the archives for previous threads over this.

I didn't find anything in a quick search, but I believe you.

Would declaring the variable (ret) 'volatile' let us remove the cast?



Get the latest Windows Live Messenger 8.1 Beta version. Join now. http://ideas.live.com

reply via email to

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