it's undefined behaviour. there are two statements in one expression.
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-39334
What is wrong with You people? How it could possibly be 01? that would mean i++ evaluates to 1 two consecutive times! This better not happen regardless the order of evaluation! :D Consider v = v ...
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-38027
I hope the result of the voting isn't undefined.
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-37803
If I didn't know any better, I would assume the following based off of the OOO. v = i++; // Just evaluating this expression. v // place address of v on the stack, increment i (i == 1); i++ // loa...
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-37644
I was only thinking yesterday that everyone knows what multiple uses of i++ should do so why don't that define it properly in the standard? I figured maybe compilers have better opportunity to op...
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-37015
Herb I'm ready for a new blog post now... :)
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-36697
It seems that some form of extra control for postincrement/postdecrement is needed in the expression.I propose using redundant parentheses around expression whenever we want the accumulated incre...
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-36353
Raptor attack. http://xkcd.com/292/ Just don't.
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-36341
i think output should be 02 .Because : std::vector
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-36309
(In the following, = is used for assignment, and == for equality.) If we were to evaluate left to right: before => v == 0, v == 0, i == 0 v = RHS => v = RHS, i == 1 v = i++ => v = 1, i == 2 after...
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-35858
Scratch that, was thinking of ++i, should print 00, it's messed up anyhow, who would do that? Why count it twice?
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-35367
But after line three has been evaluated, i would be 2, a curiosity this poll question does not touch on.
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-35366
Code should be evaluated left to right when piped (multiple times), reduced on both sides before assigned from the right side and evaluated one line after the other in order. Therefore the correc...
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-35365
There's also the question if `i == 2` at the end of that expression.
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-35354
Suppose we were doing this with a user-defined type, so instead of v=i++; we had v.operator[](i.operator++())..operator=(i.operator++()); In this case, we have unspecified behavior (feel free...
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-35110
Preferably a compile time error stating that post-increment is illegal syntax.
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-34989
What is going to become of this poll anyway? Will it sound the death knell for N4228?
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-34865
I'm a UB man (it'll learn people not to write this stuff!) followed by a 0 1 man, because I expect an RHS expression to be calculated before the LHS storage location is calculated. I particularly...
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-34801
I voted for 10 because I think the left-hand expression should be evaluated first. The command a = b translates in my mind to a.operator=(b), and it's more natural to know the type of "a" (and th...
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-34609
My vote goes for the 00 result. I haven't tested current results, but "in my mind" that is an "assignment" and that involves two different expressions. As I would do if I faced a blackboard with ...
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-34585
I'm still voting for compiler diagnostic. In that specific case (i++ twice) this is obvious. For more devious constructs where the compiler can't conclude (i++ vs j++ with names so defined that t...
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-34352
This should definitely be a compile error. Not even a warning, but a hard error. This code is undefined behavior, and every compiler we know of is able to analyse local code and figure out double...
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-33857
Taking into consideration the following: u = v =
i++;
and the fact that operator++ could be user defined, and
the fact that operator= associates right-to-left, it makes sense to
expa...
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-33852
int i = 0; v = i++; Herb, by the way, after looking a bit closer, the postfix looks correct by logic, because the vector being an internal system based feature is close to the language itself, a ...
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-33713
int i = 0; v = i++; There's nothing here that seems much afoul here. One would just be dealing with two logic layers of abstraction. Usually if you see code like that in a file, the person has th...
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-33712
I'd like this being (in standard's terms) "ill formed (no diagnostics required)". That's almost status quo (as far as I can tell it's answer 5). You cannot do any real justice among the "good" an...
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-33432
10 (if my in-mind compiler served me right), i.e left to right. This really boils down to "what is easier to teach to a beginner" - in which case it seems pretty obvious to me. C++ is read by peo...
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-33340
"12" should be the answer. Think about Ms. Liskov: /* following
the Liskov idea of substitution... */ #include
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-33339
@Michael (Post-)incrementing as the last operation of the full expression would, among other things, break existing code, since as things stand now, side effects of arguments to a function must b...
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-33264
Do we have something like f(g(i++),i++); here? I like 00 because it can be phrased as a simple rule - if several sub-expressions of single statement contain post increments than incrementing is t...
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-33252
Can anyone explain why this doesn't invoke the fill constructor?
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-33206
I vote for 10 as I prefer left-to-right evaluation, which goes the same way that a human reads the code. But if this can cause compilers to miss optimization opportunities, I would go with unspec...
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-33187
Is there a value in letting different compilers deal with things like this their own ways rather than to standardize a particular behavior? Personally I prefer things things to be standardized as...
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-33153
In reply to hyrosen. So does C#. Its not like Herb doesn't know this already. As always with ...
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-33147
In reply to Eric. Finally! a voice of reason!
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-33146
(really? - strips links without allowing me to edit?) Search stackoverflow for "What are the rules for evaluation order in Java?"
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-33140
Commenting on own post - Initially I read 00 to imply no writes - as noted by others it can imply r to l evaluation. Remainder of my comment stands. I don't have an issue with getting rid of unde...
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-33139
This is why people go off and create their own programming languages. I know that I'm right, but I have long since given up hope that C/C++ will ever do it - I've been arguing about this for year...
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-33133
In reply to Matt C. @Matt C, the compiler won't know in general which of f_1(i) or f_2(i) wil...
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-33131
So when I looked at the question, I immediately thought, "I would expect this to execute left-to-right". v => lhs = v, i = 1. i++ => rhs = 1, i = 2. lhs = rhs => v = 1. So that gives the "10" res...
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-33129
In reply to Joseph Mansfield (@sftrabbit). @Joseph Mansfield: I don't understand the C++ comm...
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-33124
In reply to Evan. @Evan -- are you serious? I can't tell.
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-33123
From a first look I would expect it to write 0 to v, so {0,0}. Why? - Right side is executed first (the value has to be generated before you can assign it). - i++ returns 0, i is now 1 - After th...
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-33121
I would expect it to write 0 to v, so {0,0}. Why? - Right side is executed first (the value has to be generated before you can assign it). - i++ returns 0, i is now 1 - After this the array is ac...
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-33120
I voted for unspecified for two reasons: 1. I do not like the idea of enforcing further sequencing rules on expressions. The current sequenced-before rules are intuitive and map nicely to the syn...
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-33105
@Evan I'm utterly baffled why you would want a statement in a programming language, which is written for no other purpose than asking a computer to produce a desired result, to have an ambiguous ...
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-33082
@Evan, thanks for that explanation! Much appreciated.
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-33071
@Ben Craig > I would prefer: “Unspecified (one of the first three options, but could be different on different compilers, or even different runs of the same compiler)”. I would want something...
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-33061
@bdsoftware: > Thus, the only two possible outputs would be 00 and 10.
i don’t see how 01 could ever happen. That's because you're not
thinking creatively enough. Consider just https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-33060x = y++
it seems simplest to have the above work similar to the way
*pDest++=*pSrc++;
works
https://herbsutter.com/2014/12/01/a-quick-poll-about-order-of-evaluation/#comment-33058