This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Why doesn't combine like volatiles? (volatile_ok again, sorry!)


On Nov 28, 2005, at 3:00 AM, Richard Earnshaw wrote:
Possibly, but I think the more interesting observation is listed in
parenthesis: Can a volatile access ever alias a non-volatile access?
Logic would suggest that a program is unpredictable if written in such a
way that permits such aliases to exist, since it would mean a location
is being accessed in both non-volatile and volatile manner.

I think this is uninteresting, as I'd presume that it is valid, and the user really wanted to do it (the below is pseudo code, no, really):


int i[4096];

void foo() {
    i[0] = 0;
    mmap (... &i[0], ...);
    (*(volatile int *)&i[0]) = 1;
}

Anyway, why it is uninteresting is, the normal rules say they alias, so they alias. And for people that just want to quote the standard, don't bother, let me:

       [#5] If an attempt is made to modify an object defined  with
       a  const-qualified  type  through use of an lvalue with non-
       const-qualified type, the  behavior  is  undefined.   If  an
       attempt  is  made  to  refer  to  an  object  defined with a
       volatile-qualified type through use of an lvalue  with  non-
       volatile-qualified type, the behavior is undefined.102)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]