mdh said:
Be warned. /Precedence/ and /order of evaluation/ are not the
Meaning that things that will happen will be as expected,( versus
undefined) except that "my" anticipated order ( with exceptions you
mentioned) can not be relied upon?
No.
Meaning that the compiler can use any order it likes, as long as the
correct operands are used for each operator.
........
So it sounds like "associativity" and "binding" is synonymous?
So, may I try and summarize what you have told me?
Precedence "asscociates" an operand with an operator ( unary
operator), or 2 operands with and operator.
Almost.
The combination of precedence and associativity can tell you (in most
cases) which operands an operator works on.
Basically, precedence and associativity tell you how to create a fully
parenthesised expression that is equivalent to the original expression.
As an example, we take the expression
*s++ = 12
Precedence tells us that = has low precedence, and ++ and * have the
same, higher, precedence. This leads to the parenthesised form
(*s++) = 12
Because * and ++ have the same precedence, we can't use that to place
further parentheses. Now associativity comes into play. The
associativity of these operators is 'right to left', so that is the
order in which we should place our next parentheses:
(*(s++)) = 12
Now it is clear that the * operates on the result of the expression s++.
This is very different
from evaluating an expression. (I looked for a definition of
evaluation, and did not find one, but I suppose conceptually it is the
act of "resolving"? an expression.) What you have said is that with
exceptions, the language does not specify an order in which this is to
occur..and I guess, one has to be careful in crafting code to be
unambiguous, in this regard.
Or even better, write code that does not care about the order of
evaluation.
So, to go back where this all started:
int zog[2] = { 6, 42 };
int *s;
s = zog; *s++ = 12;
/* zog is now { 12, 42 }, *s = 42 */
The deference happens as part of the assignment; the increment
happens sometime between the beginning of the statement and the
end.
means: ( (*(s++)) = 12 ); /** in terms of precedence **/
In terms of the combination of precedence and associativity. (or more
correct: in terms of the language grammar).
Now...I hope I don't get you pulling your hair out ....but...does the
's++' imply that s will only increment AFTER something has happened to
it, which in this case is to have the '12' assigned to that which it
points at, now it is incremented, then it is dereferenced?
Not exactly.
You can interpret 's++' best as: Schedule an increment of s and continue
working with the old value.
In the same way, ++s can be read as: Schedule an increment of s and
continue working with the new value.
For a well-formed program, it does not matter when the compiler finally
gets around to perform the scheduled increment.
I think
that I am still a little fuzzy as to the exact meaning of
"evaluation" and "precedence/assocition"..or it may just be too damn
late/early in the morning?

In other words, is 's++' an evaluation
or an 'association'? Is it obvious to you what I am perhaps missing?
I would call it both.
To me, association is the process of determining which operands an
operator works on, so the operator++ is associated with the operand s.
Evaluation is more a runtime thing, where the actual calculation is
performed.
Bart v Ingen Schenau