* Prasoon Saurav, on 22.05.2011 11:40:
> Why does post increment ++ has higher precedence than pre increment +
> +?
>
> This question appeared at stackoverflow.com :
> http://stackoverflow.com/questions/6...refix-operator
>
> One of the answers mentioned that this was because the designers of
> the language decided so.
> My question is why did the language designers (people who designed the
> grammar of the language) decide to do so?
First, the C++ standard does not define an operator precedence, and even before
the standardization there was never a defined precedence.
Instead, the effective operator precedence that you see, and that is documented
in many books, and which is not a perfect one!, results from the grammar.
So the question is, why is the C++ grammer defined so that
++o++
parses as
++(o++) // A
rather than
(++o)++ // B
?
Well, parse A yields an error at compilation time (you cannot increment an
rvalue), while parse B yields Undefined Behavior at run time.
Which would you rather have?
Cheers & hth.,
- Alf
--
blog at <url: http://alfps.wordpress.com>