News for hackers. Stuff that matters.
Re:Int a = 5; a = a++ + ++a; a =? (2011) by HarHarVeryFunny on Thursday May 14, 2026 @08:11PM (#48142899)
It's only the order of evaluation that is undefined.
Re:Int a = 5; a = a++ + ++a; a =? (2011) by afdbcreid on Thursday May 14, 2026 @08:43PM (#48143118)
Nope, there is no sequence point in the middle and modifying an object more than once between sequence points is undefined behavior.
Re:Int a = 5; a = a++ + ++a; a =? (2011) by _kst_ on Thursday May 14, 2026 @08:58PM (#48143207)
No, the behavior is undefined. That means, quoting the ISO C standard, "behavior, upon use of a nonportable or erroneous program construct or of erroneous data, for which this document imposes no requirements".

A conforming implementation could reject it at compile time, or generate code that traps, or generate code that set a to 137, or, in principle, generate code that reformats your hard drive. Some of these behaviors are unlikely, but none are forbidden by the language standard.

Re:Int a = 5; a = a++ + ++a; a =? (2011) by HarHarVeryFunny on Friday May 15, 2026 @08:53AM (#48147976)
I was wrong.

I was looking at this:

https://en.cppreference.com/cpp/language/eval_order

I'm not sure where precisely this sequencing exception to the default "eval order undefined" rule is given, but after the 24(!) sequencing rules they do give this "++i + i++" as an explicit example of undefined behavior.

Interestingly that page says that since C++17 f(++i, ++i) is "unspecified" rather than "undefined", whatever that means, and presumably plus(++i, i++) would be too, which seems a bit inconsistent.