From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,64afbf156d06bbe7,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-09-26 04:37:41 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!bloom-beacon.mit.edu!nycmny1-snh1.gtei.net!news.gtei.net!newsfeed.mathworks.com!fu-berlin.de!uni-berlin.de!62.173.119.178!not-for-mail From: Peter Amey Newsgroups: comp.lang.ada Subject: 'Valid, subtypes and constraint checking Date: Fri, 26 Sep 2003 12:41:59 +0100 Message-ID: NNTP-Posting-Host: 62.173.119.178 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de 1064576257 7107665 62.173.119.178 (16 [69815]) User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: en-us, en Xref: archiver1.google.com comp.lang.ada:42979 Date: 2003-09-26T12:41:59+01:00 List-Id: 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