Il 02/07/2010 3.58, pete ha scritto:
[...]
Your meanings associated with these following statements:
++*s = ++*t;
(*s)++ = (*t)++;
suggest that you think that those statements can compile.
Just a question (for my personal benefit, in order to understand)
why they are not lvalues?
Most C operators yield "free-floating" values, plain values
that are derived from "stored values." You can write `y = x + 1',
and all is well: the `+' operator inspects its two operands `x' and
`1', and yields their sum, and the `=' operator can store that sum
in the spot designated by the left-hand side. But you cannot write
`x + 1 = y', although it looks mathematically identical: The addition
operator inspects its operands `x' and `1' and yields their sum, but
it's a "free-floating" value, not a variable in which the value of
`y' could be stored. C's assignment operator is spelled `=', but it
doesn't have the mathematical meaning of "equals," it has the C
meaning of "assign."
So, let's look at the two proposed assignments with this
in mind:
`++*s = ++*t': Each side is well-formed and well-defined.
`++*s' is "the value of whatever s points at, incremented." That
is, it's "something plus one," plus a side-effect. Just as you
can't write `x + 1 = y', you can't write `this + 1 = that'.
`(*s)++ = (*t)++' runs into a similar problem. The left-hand
side is "the value of whatever s points at, and arrange for that
thing to be incremented sometime soon." The value, once extracted,
is again a "free-floating" value, not someplace you can store some
other value. (If you could, when would the incrementation happen
and what would it mean?)
Many programming languages are like this: There's a way of
referring to an object for the purpose of extracting its value,
and another way of referring to it for the purpose of storing a
new value. The latter purpose is usually limited in various ways:
Loosely speaking, you can name the variable you want to store to,
but can't at the same time derive a value. Or, in less high-flown
terms, you can't write `a*x*x + b*x + c = 0' and expect to have a
quadratic root extracted and assigned to `x'!