Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Re: Post increment ++ has higher precedence than pre increment ++. Why?

Reply
Thread Tools

Re: Post increment ++ has higher precedence than pre increment ++. Why?

 
 
Alf P. Steinbach /Usenet
Guest
Posts: n/a
 
      05-22-2011
* 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>
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
why prefix increment is faster than postfix increment? jrefactors@hotmail.com C++ 99 06-11-2010 12:51 PM
post increment or pre increment? Peng Yu Perl Misc 7 11-23-2008 11:44 PM
why prefix increment is faster than postfix increment? jrefactors@hotmail.com C Programming 104 10-27-2005 11:44 PM
to_s precedence higher than -@ for Infinity ? trans. (T. Onoma) Ruby 4 10-11-2004 05:20 AM
pre, post increment standard behaviour, and friend function declaration eddiew_AUS C++ 18 01-27-2004 04:31 PM



Advertisments