If we have three functions (foo, bar, and baz) that are composed like so…
foo(bar(), baz())
Is there any guarantee by the C++ standard that bar will be evaluated before baz?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No, there’s no such guarantee. It’s unspecified according to the C++ standard.
Bjarne Stroustrup also says it explicitly in “The C++ Programming Language” 3rd edition section 6.2.2, with some reasoning:
Although technically this refers to an earlier part of the same section which says that the order of evaluation of parts of an expression is also unspecified, i.e.