This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: access to a volatile variable
- To: mrs at wrs dot com (Mike Stump)
- Subject: Re: access to a volatile variable
- From: Alexandre Oliva <oliva at dcc dot unicamp dot br>
- Date: 20 Jun 1999 03:51:29 -0300
- Cc: nathan at cs dot bris dot ac dot uk, osv at Javad dot RU, egcs-bugs at egcs dot cygnus dot com
- References: <199906181624.JAA05363@kankakee.wrs.com>
On Jun 18, 1999, mrs@wrs.com (Mike Stump) wrote:
> I think that is perfectly clear and correct. *vpi; means fetch.
I disagree. [expr.unary.op] says:
1 The unary * operator performs indirection: [...] the result is an
lvalue referring to the object or function to which the expression
^^^^^^^^^^^^^^^^
points. [...]
But [basic.lval] says:
7 Whenever an lvalue appears in a context where an rvalue is expected,
the lvalue is converted to an rvalue
So the question is whether the lvalue-to-rvalue standard conversion,
that fetches the value referred by the lvalue, is performed or not.
In the cast-to-void case, it's easy, as [expr.static.cast] says:
4 Any expression can be explicitly converted to type cv void. [...]
The lvalue-to-rvalue (_conv.lval_), array-to-pointer (_conv.array_),
and function-to-pointer (_conv.func_) standard conversions are not
applied to the expression. ^^^
So `(void)*pvi;' must *not* fetch the value, whereas `+*pvi;' *must*
fetch it (assuming that unary+ expects an rvalue, which is not
explicitly stated in its definition, but can be implied from
[over.built]/10, where operator+ takes its argument by value, not by
reference)
But what about plain `*pvi;'? The answer is in [stmt.expr]:
1 Expression statements have the form
expression-statement:
expressionopt ;
The expression is evaluated and its value is discarded. The lvalue-
to-rvalue (_conv.lval_), array-to-pointer (_conv.array_), and func-
tion-to-pointer (_conv.func_) standard conversions are not applied to
the expression. ^^^
Therefore, `*pvi;' must not fetch any value, while `(int)*pvi;' must.
--
Alexandre Oliva http://www.dcc.unicamp.br/~oliva IC-Unicamp, Bra[sz]il
{oliva,Alexandre.Oliva}@dcc.unicamp.br aoliva@{acm.org,computer.org}
oliva@{gnu.org,kaffe.org,{egcs,sourceware}.cygnus.com,samba.org}
*** E-mail about software projects will be forwarded to mailing lists