A question on volatile accesses
Henry Spencer
henry at zoo.toronto.edu
Sun Nov 4 10:18:56 AEST 1990
In article <2388 at lupine.NCD.COM> rfg at lupine.ncd.com (Ron Guilmette) writes:
> volatile int *ip;
> i = *++ip;
>
>I'd like to know if the standard allows the incrementation of `ip'
>to occur *after* the volatile access.
It depends on what you are asking. If I am not mistaken, it is proper for
the change to `ip' -- the variable -- to occur only after the access.
However, the access itself *must* use the incremented value, even if that
value has not yet been written back into the variable; the definition of
the prefix `++' operator demands this.
>In other words, could the program above legally be treated as:
> i = *ip;
> ++ip;
No, although it could be treated as:
i = *(ip + 1);
++ip;
The volatility of the thing pointed at, by the way, has absolutely no
bearing on the issue (except insofar as a kludged-in implementation of
`volatile' may have introduced bugs).
>This seems entirely counter-intutive to me, and yet one supposedly ANSI
>C compiler provides such a treatment.
Your use of the word "supposedly" is appropriate. The way you asked this
implies that this doesn't happen if the thing pointed at is not `volatile'.
My diagnosis would be as mentioned above: somebody kludged `volatile' into
a compiler that originally didn't support it, and broke the prefix `++'
operator in the process.
--
"I don't *want* to be normal!" | Henry Spencer at U of Toronto Zoology
"Not to worry." | henry at zoo.toronto.edu utzoo!henry
More information about the Comp.std.c
mailing list