Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Bounds and overflow checking, both on array accesses and on arithmetic

I like that one. Anyone know any widely adopted languages that do this?



Rust has support for both of these, though the arithmetic overflows are effectively opt-in. Rust does define exactly what happens in overflow situations, and allows you to use different functions for controlling overflow options in others.


It's a little glib, but Python 3 (and Ruby, I believe) both has checked array access and vacuously has overflow checking given integers can't overflow (by default).


Seems to be at runtime so, so almost every language for bounds checking.

Overflow checking is a bit more rare:

* Swift has it by default (error)

* So do Python, Ruby, Erlang (promotion to arbitrary precision)

* C# has an optional Checked Context though I don't know how common it is

* Rust has checked operations (opt-in, both error and saturating), will check (error) by default in debug mode, it can optionally check (error) in release mode


Idris has compile time bounds checking.

It is a pretty special case though, you have to jump through a number of hoops using dependent types to get it.


> Idris has compile time bounds checking.

Indeed it does, but I'm guessing it doesn't come close to qualifying for "widely adopted language", my list is already stretching it.


Both GCC and Clang have an extension to C that provide __builtin_xxx_overflow methods:

GCC: https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins...

clang: https://clang.llvm.org/docs/LanguageExtensions.html#checked-...


Nim, but you can turn it off if you want


Sorry, I'm confused, does bounds checking mean index out of bounds? If so, most modern languages?


I think the question was more about bounds checking on arithmetic, which most modern languages don't do by default.


Fortran


Swift

C# has the ability to opt-into default checked arithmetic. I don't know of anyone that uses it...


Ada?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: