back

by uecker·2y ago·view on hn ↗
I think modular behavior at run-time is actively dangerous. It is not memory-unsafe, but still unsafe. Having it trap would better. For C, you can tell the compiler to trap for signed overflow.
1 comments
IMO, that's a job for the type system. But if you can only have one option, clearly an error is the best one.

Anyway, none of those are anything nearly as damaging as C's UB. All of them are reasonable, on the literal sense that you can reason about them, anticipate what your program may do, and defend against the problem (or shrug it off and claim "it doesn't matter here"). You can do neither with by the spec C.

I do not think C's UB is damaging. As I said, you instruct the compiler to insert a trap and then it is not unsafe.

Example: https://godbolt.org/z/Kvrrx19Pa

The UB in the spec is exactly what makes safe use possible without enforcing it everywhere, which is not feasible for C.