From: rgilbert@unconfigured.xvnews.domain (Bob Gilbert)
Subject: Re: Zoo question
Date: 1996/08/14
Date: 1996-08-14T00:00:00+00:00 [thread overview]
Message-ID: <4usdkl$fg6@zeus.orl.mmc.com> (raw)
In-Reply-To: 320F16B6.6944@lmtas.lmco.com
In article <320F16B6.6944@lmtas.lmco.com>, Ken Garlington <garlingtonke@lmtas.lmco.com> writes:
> 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?
>
> package Zoo is
>
> type Animal_ID is range 1 .. 5; -- yes, an enumeration type might be
> -- better, but it spoils the example!
{snip}
> 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;
I assume that the tricky part is that the attribute 'Succ operates
on the base type of Animal_ID, which is of type integer, and does not
consider the constraint 1 .. 5 (although the attributes 'First and
'Last do). That is if Next_Animal := 5, then Animal_ID'succ(Next_Animal)
would not raise an exception but would return the value 6. However,
I would expect an exception to occur when attempting to assign the
result back to Next_Animal, so the code would probably produce the
expected result (or perhaps not?).
Of course using an enumeration type for Animal_ID would avoid the
confusion.
Is this any different for Ada 95?
-Bob
next prev parent reply other threads:[~1996-08-14 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 ` Robert A Duff
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 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
1996-08-14 0:00 ` Paul Hussein
1996-08-14 0:00 ` Bob Gilbert [this message]
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-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