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

Explicit bounds everywhere mean that those bounds need to be automatically checked every time instead of only where explicitly specified by the programmer. This leads to safer code at a nontrivial performance tradeoff, one which would not be acceptable for C.


You could imagine bounds being baked into the types and checked at compile time.

    int{0..10}  foo  = 4
    int{0..10}  bar  = 5
    int{0..10}  buzz = foo+bar                // ERR: 10+10 potentially > 10
    int{0..10}  boom = wrapping_add(foo, bar) // OK
    int{0..100} sum  = foo+bar                // OK
There are tools which can do this, for example Code Contracts in C#. It becomes rather tedious and verbose so is something usually only left for very safety critical code.


This could be useful in C for some situations. That said, the above is completely useless if just only one of those values (ranges or assignments) is dynamic: you'll be back to carefully (and manually) checking you don't overflow.*

*edit: unless your compiler automatically emits instructions to do the check at runtime; a thing that won't happen (and I don't want) in C.


Something that Ada, Modula and Pascal compilers are able to optimize away in most cases.

C keeps targeting an hardware model that even most Arduinos are super computers by comparisasion.




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

Search: