10 ms·
That’s (IMO) the right way to do it, but it’s also a harder pill to swallow from the C standards side: functions that die as a side effect rather than being UB
by woodruffw 3y ago
That’s (IMO) the right way to do it, but it’s also a harder pill to swallow from the C standards side: functions that die as a side effect rather than being UB are less precedented, have to be taught differently, etc.
C’s lack of iterators also means that indexing bugs are more likely in idiomatic C programs than they are in equivalent C++ or D programs. This is another place where the standards body should improve things, but it also means that they’re somewhat constrained when it comes to slice proposals: making every index be potentially fatal is less palatable when your programming language doesn’t divert people away from indexing as much as it could.
- CodesInChaos 3y agoSince dying is a valid implementation of UB, I don't see a problem. It's definitely better than memory corruption. In general my preferred way to handle OOB is an unchecked exception (like in Rust or C#), but that's not really an option C.