News for hackers. Stuff that matters.
Re:Erg: a statically typed language that is Python compatible by kevin_thibedeau on Sunday August 14, 2022 @02:12AM (#32456842)
Overflowing integers is not a bug. It's literally how an adder circuit operates on fixed precision. Ignoring them by default is worth criticizing but there are plenty of times where silent overflow is correct and desirable behavior.
Re:Erg: a statically typed language that is Python compatible by still_grokking on Sunday August 14, 2022 @02:43AM (#32456992)
> but there are plenty of times where silent overflow is correct and desirable behavior

When or where?

I would say it's always a bug in a program—except when (mis)using ints as bit-fields in very special circumstances.

Simply, as more or less every computation in the real world is build around the concept of whole numbers, and not around the idea of overflowing two-complement bit-fields.

The later is so exotic that there is afik almost no proper use for it (the only exception being as a very low level building block to enable computers do actually useful calculations).

Re:Erg: a statically typed language that is Python compatible by tomp on Sunday August 14, 2022 @02:22AM (#32456895)
It's technically not a "bug" in Rust or C++, it's undefined behaviour, which is much worse than a bug! (and it's never correct behaviour)
Re:Erg: a statically typed language that is Python compatible by still_grokking on Sunday August 14, 2022 @02:52AM (#32457056)
Little nitpick:

In C/C++ it's "only" UB for signed ints.

For unsigned ints it's arithmetic modulo 2^n (where n is the number of bits in the value representation of that particular size of integer).

Such divergent definitions make the whole mess of course even bigger, that's not the point.

Re:Erg: a statically typed language that is Python compatible by pratk on Sunday August 14, 2022 @04:38AM (#32457575)
Also, the UB can be mitigated with -fwrapv (if desired) to handle overflowing integers with 2's complement
Re:Erg: a statically typed language that is Python compatible by still_grokking on Sunday August 14, 2022 @05:12AM (#32457739)
Stupid question, but how can a compiler flag "mitigate" some UB that is (to my knowledge) defined by the standard as UB?

This would be possible only if the standard would define the behavior in question as implementation defined. But that's not the case afaik.

Signed overflow is undefined behavior as it's afaik defined to be that. But maybe I'm just wrong here?

But at least SO is confining my knowledge:

https://stackoverflow.com/questions/16188263/is-signed-integ...

Re:Erg: a statically typed language that is Python compatible by pratk on Sunday August 14, 2022 @12:14PM (#32460415)
-fwrapv forces the compiler to handle signed overflow with 2's complement. UB essentially means the compiler is free to do anything, and with the option it chooses the wrapping behavior. See https://stackoverflow.com/questions/47232954/what-does-fwrap...
Re:Erg: a statically typed language that is Python compatible by steveklabnik on Sunday August 14, 2022 @07:34AM (#32458405)
It’s not UB in Rust.