News for hackers. Stuff that matters.
Re:Int a = 5; a = a++ + ++a; a =? (2011) by tengwar2 on Thursday May 14, 2026 @05:43PM (#48141657)
Not nasal demons in this case (https://groups.google.com/g/comp.std.c/c/ycpVKxTZkgw/m/S2hHd...): thaumasiotes shows that we can expect a numeric answer.
Re:Int a = 5; a = a++ + ++a; a =? (2011) by _kst_ on Thursday May 14, 2026 @06:27PM (#48142096)
I don't see the name "thaumasiotes" at that link, nor do I see anything relevant to the code in the title.

The behavior of "int a = 5; a = a++ + ++a;" is undefined. There is no guarantee of a numeric result, because there is no guarantee of anything.

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.

Re:Int a = 5; a = a++ + ++a; a =? (2011) by susam on Thursday May 14, 2026 @06:36PM (#48142172)
I believe they were referring to thaumasiotes's thread here: https://news.ycombinator.com/item?id=48141294

I think the objection thaumasiotes has raised there is valid and I have made an attempt to answer it as well in the same thread.