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

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -