Is there any good reason for operator =
not being a sequence point? Both in C and C++.
I have trouble thinking about an counter-example.
because there is no sequence point specified for the assignment, increment or index operators, you don't know when the effect of the increment on i occurs. The sequence points laid down in the Standard are the following: The point of calling a function, after evaluating its arguments.
The basic advantage of compound assignment operators is that it saves a lot of code within the Java language program.
The assignment operator = assigns the value of its right-hand operand to a variable, a property, or an indexer element given by its left-hand operand. The result of an assignment expression is the value assigned to the left-hand operand.
By request:
In general, things need a reason to be a sequence point. They don't need a reason not to be a sequence point; that's the default.
For example, &&
must be a sequence point because of short-circuiting behaviour: if the left-hand side is false, the right-hand side must not be evaluated. (This is not just about optimization; the right-hand side could have side effects, and/or depend on the left-hand side being true, as in ptr && ptr->data
.) Therefore the left-hand side must be evaluated first, before the right-hand side, in order to see if the right-hand side should be evaluated at all.
This reason does not exist for =
because, although there is "evaluation" to do for both sides (although there are different restrictions on what can appear on both sides: the left-hand side must be an lvalue - the l
doesn't stand for "left", btw; it stands for "location", as in location in memory - we can't assign to a temporary or a literal), it doesn't matter which side is evaluated first - as long as both sides are evaluated before the actual assignment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With