Making Errors errors
Paul Backus
snarwin at gmail.com
Fri Jan 29 00:39:08 UTC 2021
On Thursday, 28 January 2021 at 23:41:44 UTC, sighoya wrote:
> Given range indexing as an example, we would certainly think of
> index violations as bugs. That may be true. However, the code
> following after the random access wouldn't be executed anyway
> and the caller may or may not depend hard on the result of the
> code fragment.
If out-of-bounds array access is defined by the language spec as
an unrecoverable error, an optimizing compiler is allowed to
assume that no program ever recovers from it, and potentially
re-order code based on that assumption. So you cannot actually be
sure that "the code following after the random access wouldn't be
executed."
Of course, the key phrase here is "defined by the language spec."
As a language designer, you are free to define out-of-bounds
indexing as either recoverable or unrecoverable. But as a
programmer, once the decision has been made and the spec has been
written, you do not get a choice--either you play by the rules,
or your code is wrong.
I suspect a lot of the confusion on this issue comes from people
mixing up the programmer's perspective and the language
designer's perspective.
More information about the Digitalmars-d
mailing list