|
|
|
|
|
by skitter
1070 days ago
|
|
I agree with your point about Python, which is why I'm glad type hints see adoption but dismayed that they're essentially fancy comments that don't enforce the actual runtime types. The thing is, I'm not convinced avoiding UB is easy. E.g. what's the behavior of the following code? int16_t a = 20000;
int16_t b = a + a;
|
|
Integer overflow will result, I’m pretty sure. The largest value a signed 16 bit (so, 15 bit) can hold is 32767, IIRC.
I can see where that’s unexpected for people whose brains aren’t wired in powers of 2. This is one area where I think Rust improves upon C, with its availability of overflow detection in arithmetic. It’s unfortunately verbose, but it enables greater safety.