From: Peter Amey <peter.amey@praxis-cs.co.uk>
Subject: 'Valid, subtypes and constraint checking
Date: Fri, 26 Sep 2003 12:41:59 +0100
Date: 2003-09-26T12:41:59+01:00 [thread overview]
Message-ID: <bl18e1$6ot2h$1@ID-69815.news.uni-berlin.de> (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
next reply other threads:[~2003-09-26 11:41 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-09-26 11:41 Peter Amey [this message]
2003-09-26 13:13 ` 'Valid, subtypes and constraint checking 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
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox