comp.lang.ada
 help / color / mirror / Atom feed
* 'Valid, subtypes and constraint checking
@ 2003-09-26 11:41 Peter Amey
  2003-09-26 13:13 ` Jean-Pierre Rosen
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Peter Amey @ 2003-09-26 11:41 UTC (permalink / raw)


Some guidance please to reduce the slight panic I am suffering from.

When reading in values from an external device it is important to check 
that the value read is a valid representation for its type.  The read 
values are also considered volatile so each read returns a potentially 
different value.

I have alsways believed the way to do this is:

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;

I have also assumed that applying 'Valid to the volatile value 
(ExternalPort) is pointless because, even if the check passes, any 
subsequent use of ExternalPort may return a different (perhaps invalid) 
value.

My confidence has now been shaken by a test case for a compiler, as yet 
unnamed, which raises constraint error for the initial assignment of an 
invalid value in ExternalPort to Temp.  Is this correct behaviour?  If 
it _is_ correct, how can you ever validate external volatile data?

(Horrible strawman solution: do an unchecked conversion of External_Port 
into Temp and then do the validity check).

Thoughts?



Peter




^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2003-10-01 12:44 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

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