Jump to content
  • Advertisement
Sign in to follow this  

Order Of Operation

This topic is 4018 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Semantic nitpick: This is operator precedence, not order of operation.

In the C++ expression:
a()*b() + c()*d()

This means that this is equivalent to:
(a()*b()) + (c()*d())

Rather than, say:
a() * (b()+c()) * d()

However, the calls a(), b(), c(), and d() could occur in any order. The only guarantees the C++ standard makes are:

1) a() and b() will have been evaluated when operator*(a_result,b_result) is evaluated
2) c() and d() will have been evaluated when operator*(c_result,d_result) is evaluated
3) operator*(a_result,b_result) and operator*(c_result,d_result) will have been evaluated when operator+(ab_result,cd_result) is evaluated.

Similarly, the left-to-right associative precedence of most arithmetic operators only means that:

Is equivilant to:

Rather than:

Rather than specifying an order in which a(), b(), and c() would be evaluated in.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!