This is the mail archive of the gcc-bugs@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]

Re: access to a volatile variable


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


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