0

When this code run, i in the b[a[i]] already increase before meeting ;.

b[a[i]] = i++

Let's suppose i is 0 now. I expect that this would be b[a[0]] = 0++; But, this looks like b[a[1]] = 0++; My understanding is that i++ increase when i++ meet ;. But, It seems not. Can I get some ideas?

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • The order of evaluating the LHS and RHS are not specified (although I think this might have been changed in a very recent revision). So it can be either and the behavior is undefined. – Barmar Mar 31 '22 at 19:24
  • @Barmar: The order of evaluating the left and right sides is not just not specified; the evaluations of the left and right sides are *unsequenced*. This means they might not have any order at all; a C implementation could evaluate part of the left side, part of the right side, part of the left side, part of something common to both, part of the right side, and so on. These parts can even be individual byte updates of the `i++`, so that the bytes forming `i` are neither all bytes of the pre-increment nor bytes of the post-increment. “So it can be either” leaves out that it can be neither. – Eric Postpischil Mar 31 '22 at 19:44
  • @EricPostpischil Yes, that's more precise. Is it true that there's a change to the spec that does order them, or is that C++? I'm pretty sure I saw something like that recently. – Barmar Mar 31 '22 at 19:49
  • @Barmar: They are still unsequenced in C draft N2731. C++ is sequencing more things. – Eric Postpischil Mar 31 '22 at 19:56

0 Answers0