logoalt Hacker News

vlovich123 • today at 4:51 PM • 5 replies • view on HN

I don’t know any systems programming language that doesn’t ignore integer overflow/underflow in release builds. IMHO this is a CPU design flaw - integer operations should carry a flag indicating if the operation is allowed to wrap or if it should generate a trap. Then there wouldn’t be a performance penalty for this and languages like Rust could have it be trapped by default.


Replies

benlivengood • today at 6:29 PM

X86 had the INTO instruction to trigger a fault if the Overflow flag is set, so not quite a per-instruction bit but more of a suffix. JO is also fairly straightforward for compilers to add on important arithmetic operations. We can probably blame C entirely for this; only in C23 are there intrinsics for overflow detection on arithmetic.

10000truths • today at 5:10 PM

Zig traps arithmetic overflow/underflow when compiling in ReleaseSafe.

tptacek • today at 4:54 PM

No. Memory safe languages still have integer handling issues, but the consequences are different. In a memory-unsafe language, integer mishandling often nets out to bad copies and memory corruption.

➕ show 1 reply
BoingBoomTschak • today at 5:49 PM

Lisp or Python have a proper numeric tower and don't default to machine types. Keyword being default, fast is still possible in CL.

codedokode • today at 4:55 PM

"I don't know any decent language so let's continue using poorly designed languages". Please look at Swift, Javascript, Python.

Why would CPU designers make a trap if languages do not require it?

➕ show 1 reply