5 ms·
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 k
by wk_end 5y ago
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?
- Cloudef 5y agoYes, it's enforced by any _runtime_ operation. See: https://www.adaic.org/resources/add_content/standards/05rm/html/RM-3-5-4.html https://www.adaic.org/resources/add_content/standards/05rm/h...
- Jtsummers 5y agoThe 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.
- throwaway81523 5y agoUsually with runtime checks, but it can also in some situations be done statically, such as with SPARK.