This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: volatile semantics
On May 3, 2005, at 7:41 AM, Nathan Sidwell wrote:
Mike Stump wrote:
int avail;
int main() {
while (*(volatile int *)&avail == 0)
continue;
return 0;
}
Ok, so, the question is, should gcc produce code that infinitely
loops, or should it be obligated to actually fetch from memory?
Hint, 3.3 fetched.
I beleive the compiler is so licensed. [5.1.2.3/2] talks about
accessing
a volatile object. If the compiled can determine the actual object
being accessed through a series of pointer and volatile cast
conversions,
then I see nothing in the std saying it must behave as-if the object
were volatile when it is not.
This is correct; the standard consistently talks about the type of the
object,
not the type of the lvalue, when describing volatile.
However, as a QOI issue, I believe the compiler should treat the
reference as
volatile if either the object or the lvalue is volatile. That is
obviously the
user's intent.