Mail Archives: djgpp/2007/04/18/11:32:38
"Alexei A. Frounze" <alexfru AT chat DOT ru> wrote in message
news:G-CdnfEDh5KKDLnbnZ2dnUVZ_jydnZ2d AT comcast DOT com...
> Rod Pemberton wrote:
> > "Alexei A. Frounze" <alexfru AT chat DOT ru> wrote in message
> > news:LbadnVsa3_H-ornbnZ2dnUVZ_sudnZ2d AT comcast DOT com...
Very sleepy now on a topic I'm not well versed on... This, from n1124
6.7.3, as I read it, seems to apply. (e.g., both the data _and_ pointer need
a volatile...)
"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.113)"
Anyway, let's ignore the spec. and see if I've got it the issues straight:
Volatile on the pointer works (i.e., f2). If the pointer is volatile, then
the data is volatile implicitly (i.e., new pointer therefore new data).
And, both optimized and unoptimized, we see the pointer being reloaded from
the stack and the data being reloaded from the pointer.
Volatile on the data doesn't work (i.e., f1) supposedly just for -O2. If
the pointer isn't volatile, but the data is, then just the data should be
reloaded. Unoptimized, the compiler treats both as volatile (both are
refreshed), i.e., incorrect. Optimized, the compiler treats both as
non-volatile (neither are reloaded), i.e, (appears) incorrect. So,
technically, both are incorrect. But, for the unoptimized case, since the
pointer isn't changing, it's functionally correct. For the optimized case,
it would appear that it's incorrect unless the compiler can somehow
determine that the data isn't changing...
Going to sleep...
Rod Pemberton
- Raw text -