This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why include all operators in the precedence hierachy?

 
Simon Smith
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am puzzled as to why all operators are listed in the precedence hierachy.

For example it makes perfect sense to have a hierachy for Addition/Multiplication operators so that you can make sense of:

int i = 4 * 9 + 3;

However, why state that the postfix increment operator is of greater precedence that the prefix increment operator? Surely, under any conditions that I can think of they would be goeverned by the associativity rule.

For example :

int i = 1;
int j = i++ + ++i;

The precednce of postfix/prefix are irrelanvent as the operands of the addition operator are evaluated left to right.

There must be a reason, so if any of you good folks could provide me with an example of why precedence rules exist for all operators I would be very grateful.

Thanks in advance,

Simon
 
wise owen
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hope this may help.
 
Simon Smith
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Thanks for that. It is an interesting article but it doesn't provide an example of when the precedence of a postfix increment over a prefix increment operator would be relevant.

Thanks

Simon
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic