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

I've always wondered - does Ada track or enforce these ranges?

Like, if I have a variable `i` in range 0...10 and write the Ada equivalent of `i++`, does Ada know that from there on out `i` is in range 1...11? Something like TypeScript's type narrowing?



Yes, it's enforced by any _runtime_ operation. See: https://www.adaic.org/resources/add_content/standards/05rm/h...


The range wouldn’t change in Ada. The type for a variable is fixed at compile time. It will ensure (at runtime and partially at compile time) that the value doesn’t go outside the range, though.


Usually with runtime checks, but it can also in some situations be done statically, such as with SPARK.




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

Search: