comp.lang.ada
 help / color / mirror / Atom feed
From: kst@thomsoft.com (Keith Thompson)
Subject: Re: Zoo question
Date: 1996/08/15
Date: 1996-08-15T00:00:00+00:00	[thread overview]
Message-ID: <Dw5usI.6xy@thomsoft.com> (raw)
In-Reply-To: 3210A142.2781E494@escmail.orl.mmc.com


In <3210A142.2781E494@escmail.orl.mmc.com> Ted Dennison <dennison@escmail.orl.mmc.com> writes:
> Ken Garlington wrote:
> > 
> > Here's a little brain teaser we received recently. Assuming no typos or
> > other obvious syntax errors, will the Fill procedure work in Ada 83?
> 
> OK. I'll bite. It looks like it would probably perform as advertised, with
> no optimization set on the compiler. The following constraint check code -
> 
> > 
> >       Get_Next_Animal: begin -- look carefully at this code!
> >         Next_Animal := Animal_ID'Succ(Next_Animal);
> >       exception
> >         when others => Next_Animal := Animal_ID'First;
> >       end Get_Next_Animal;
> 
> isn't guaranteed to work (assuming "work" means raise an execption within
> this block when Animal_ID'Succ(Next_Animal) > Animal_ID'last).

I believe it *is* guaranteed (by the language) to work.  In both Ada 83
and Ada 95, the Animal_ID'Succ attribute is a function that takes a
value of type Animal_ID'Base and returns a value of type Animal_ID'Base.
Since Animal_ID'Base will almost certainly have bounds greater than
1..5, Animal_ID'Succ(5) will return 6, without raising an exception.

However, attempting to assign the resulting value to Next_Animal *must*
raise Constraint_Error, since Next_Animal is of subtype Animal_ID and
is constrained to the range 1..5.

I can imagine a compiler implementer mistakenly thinking that the Succ
attribute returns a value of the prefix subtype, and optimizing out
the check.  If this is what you're seeing, it's clearly a compiler bug.

Incidentally, this worked as expected (i.e., properly raised
Constraint_Error) on every Ada 83 and Ada 95 compiler I tried.

-- 
Keith Thompson (The_Other_Keith) kst@thomsoft.com <*>
TeleSoft^H^H^H^H^H^H^H^H Alsys^H^H^H^H^H Thomson Software Products
10251 Vista Sorrento Parkway, Suite 300, San Diego, CA, USA, 92121-2718
"As the most participatory form of mass speech yet developed, the Internet
deserves the highest protection from government intrusion." -- ACLU v. Reno




  parent reply	other threads:[~1996-08-15  0:00 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-08-12  0:00 Zoo question Ken Garlington
1996-08-12  0:00 ` Chris Morgan
1996-08-13  0:00   ` Ken Garlington
1996-08-13  0:00 ` Ted Dennison
1996-08-14  0:00   ` Ken Garlington
1996-08-14  0:00     ` Ted Dennison
1996-08-15  0:00       ` Ken Garlington
1996-08-18  0:00         ` Robert Dewar
1996-08-19  0:00           ` Ted Dennison
1996-08-19  0:00             ` Mark A Biggar
1996-08-20  0:00             ` Robert Dewar
1996-08-15  0:00       ` Robert A Duff
1996-08-15  0:00     ` Robert Dewar
1996-08-15  0:00       ` Bob Gilbert
1996-08-19  0:00         ` Ted Dennison
1996-08-16  0:00       ` Ken Garlington
1996-08-19  0:00       ` Ted Dennison
1996-08-15  0:00   ` Keith Thompson [this message]
1996-08-14  0:00 ` Bob Gilbert
1996-08-14  0:00   ` Ted Dennison
1996-08-14  0:00     ` Bob Gilbert
1996-08-14  0:00       ` Ted Dennison
1996-08-14  0:00         ` Bob Gilbert
1996-08-14  0:00           ` Ken Garlington
1996-08-15  0:00             ` Robert A Duff
1996-08-16  0:00             ` Bob Gilbert
1996-08-19  0:00               ` Ted Dennison
1996-08-25  0:00                 ` Robert Dewar
1996-08-15  0:00           ` Robert I. Eachus
1996-08-14  0:00 ` Paul Hussein
1996-08-15  0:00 ` John Herro
1996-08-16  0:00   ` Robert Dewar
1996-08-18  0:00     ` John Herro
1996-08-19  0:00       ` Ken Garlington
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox