Ada - Any defined behavior for incrementing past end of range? -


if define range in ada being 1 .. 1000, there defined behavior ada spec if increment past 1000?

for example:

type index range 1..1000;  idx : index := 1;  procedure increment  begin   idx := idx + 1; end 

what should expect happen once call increment idx = 1000?

  • wraps around (idx = 1)
  • out of range exception
  • undefined behavior
  • something else?

your program fail constraint_error. however, not because try set idx 1001. rather initial value of 0 not within predefined range either. thankfully, compiler warn @ compile time fact.

if had set idx permitted value , incremented beyond upper limit in way compiler cannot statically detect, again constraint_error raised (but there won't hint @ compile time). error technically exception can handle other exception in language.

note: intentionally linked ancient ada '83 specs above show behavior has been part of language since beginning of time.


Comments

Popular posts from this blog

multithreading - Exception in Application constructor -

React Native allow user to reorder elements in a scrollview list -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -