News for hackers. Stuff that matters.
Re:Int a = 5; a = a++ + ++a; a =? (2011) by vcdk on Thursday May 14, 2026 @05:28PM (#48141513)
Well... tried it on macOS using vanilla gcc, the results surprised me:

  $ /bin/cat x.c; gcc -w -o x x.c; ./x
  #include <stdio.h>
  
  int main()
  {
      int a = 5;
      a += a++ + a++;
      printf("a = %d\n", a);
  }
  a = 18
Not what I expected. This must be how it works:

- The first a++ expression results in 5, after a = 6 - The second a++ expression results in 6, after a = 7 - Only then the LHS a is evaluated for the addition-assignment, so we get: a = 7 + 5 + 6 = 18

Re:Int a = 5; a = a++ + ++a; a =? (2011) by rmu09 on Thursday May 14, 2026 @05:45PM (#48141669)
the original question has a=, you have a+=
Re:Int a = 5; a = a++ + ++a; a =? (2011) by Izkata on Thursday May 14, 2026 @06:18PM (#48142021)
They're using the version from the top comment, not the post. It also switches the pre-increment to post-increment.
Re:Int a = 5; a = a++ + ++a; a =? (2011) by vcdk on Friday May 15, 2026 @02:26AM (#48145209)
I was just replying to the comment ¯\_(ツ)_/¯