comp.lang.ada
 help / color / mirror / Atom feed
From: Vinzent Hoefler <JeLlyFish.software@gmx.net>
Subject: Re: Test for > 'last
Date: Fri, 14 Mar 2003 13:10:58 -0500
Date: 2003-03-14T13:10:58-05:00	[thread overview]
Message-ID: <b4t635$22plon$1@ID-175126.news.dfncis.de> (raw)
In-Reply-To: 3e721008$0$895$9b0f33e3@clyde

"Ant" <ant@work.invalid> wrote:

>"Peter Richtmyer" <prichtmyer@yahoo.com> wrote in message
>news:1b585154.0303140406.124c3312@posting.google.com...
>> This may be trivial, but I have come across some code
>> in a (weapon control) system that does checks similar
>> to:
>>
>>     ---------------------------------------
>>     if enum_input < enum_type'first or
>>        enum_input > enum_type'last then
>>        -- handle the input error
>>     ---------------------------------------
>
>[...]
>
>> But I am wondering whether people think the original code
>> is OK, sort of wrong, really grossly wrong, or what.
>
>I would rather do this:
>
>if enum_input not in enum_type'first .. enum_type'last then
>  -- handle error
>end if;

And would be wrong, too, if enum_input also has the type enum_type.

If you look closer to this, this statement does not make sense and the
compiler is indeed not required to check this, because the contract
tells him, this condition will *always* be false (even if in fact it
might not be). What else should a enum_input contain than some value
of enum_type?

Either use 'Valid or use a type that is allowed to contain values
outside the range of the type to be compared with.


Vinzent.



  reply	other threads:[~2003-03-14 18:10 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-03-14 12:06 Test for > 'last Peter Richtmyer
2003-03-14 12:24 ` Jeffrey Creem
2003-03-14 17:22 ` Ant
2003-03-14 18:10   ` Vinzent Hoefler [this message]
2003-03-17 11:28     ` Ant
2003-03-15  2:02 ` Jeffrey Carter
replies disabled

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