comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <spam@spam.com>
Subject: Re: 'Valid, subtypes and constraint checking
Date: Fri, 26 Sep 2003 18:18:17 GMT
Date: 2003-09-26T18:18:17+00:00	[thread overview]
Message-ID: <Jp%cb.4210$RW4.2204@newsread4.news.pas.earthlink.net> (raw)
In-Reply-To: <bl18e1$6ot2h$1@ID-69815.news.uni-berlin.de>

Peter Amey wrote:

> ExternalPort : T;
> Temp  : T;    -- note same SUBtype as the port
> ...
> Temp := ExternalPort; -- no checks generated because same subtype
> if Temp'Valid then
>   -- we can use value safely
> else
>   -- handle error safely
> end if;

If External_Port can take on values not in T, then it should not be 
considered of subtype T. For example

subtype T is Unsigned_8 range 2#0000_0000# .. 2#0000_1111#;

External_Port : Unsigned_8;
for External_Port'Address use ...;
pragma Volatile (External_Port);

Temp_8 : Unsigned_8;
Temp   : T;
...
Temp_8 := External_Port;

if Temp_8 not in T then
    raise An_Appropriate_Exception;
end i;f

'Valid is perhaps more appropriate for a value obtained from 
Unchecked_Conversion, or portions of the software where it has been 
necessary to turn of checking:

External_Port : T;
-- clauses
...
declare
    pragma Suppress ...;
begin
    Temp := External_Port;
end;

if not Temp'Valid then
    raise ...;
end if;

--  process Temp

-- 
Jeff Carter
"Death awaits you all, with nasty, big, pointy teeth!"
Monty Python & the Holy Grail
20




  parent reply	other threads:[~2003-09-26 18:18 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-09-26 11:41 'Valid, subtypes and constraint checking Peter Amey
2003-09-26 13:13 ` Jean-Pierre Rosen
2003-09-26 18:18 ` Jeffrey Carter [this message]
2003-09-26 21:48   ` Chad R. Meiners
2003-09-27  1:30 ` Robert I. Eachus
2003-09-29  7:27   ` 'Valid, subtypes and constraint checking - Thanks Peter Amey
2003-09-30  2:58     ` Robert I. Eachus
2003-09-30 12:45       ` Marin David Condic
2003-09-30 21:30         ` Robert I. Eachus
2003-10-01 12:44           ` Marin David Condic
replies disabled

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