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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,fdd685ffa59d584d X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!d28g2000yqc.googlegroups.com!not-for-mail From: Mark Lorenzen Newsgroups: comp.lang.ada Subject: Re: What would be the Ada solution? Date: Fri, 4 Feb 2011 08:38:13 -0800 (PST) Organization: http://groups.google.com Message-ID: <37361431-c3a5-4b51-a2f2-aa0e0b485d60@d28g2000yqc.googlegroups.com> References: <0aa67233-4210-483b-b35c-8e872f87cb8f@r21g2000yqd.googlegroups.com> NNTP-Posting-Host: 193.163.1.105 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1296837493 31044 127.0.0.1 (4 Feb 2011 16:38:13 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 4 Feb 2011 16:38:13 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: d28g2000yqc.googlegroups.com; posting-host=193.163.1.105; posting-account=Srm5lQoAAAAEMX9rv2ilEKR6FDPapmSq User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; da; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13,gzip(gfe) Xref: g2news1.google.com comp.lang.ada:16869 Date: 2011-02-04T08:38:13-08:00 List-Id: On 4 Feb., 17:33, KK6GM wrote: > A colleague is working on some old code, written in C, that uses an > "out of range" integer value to indicate no valid value. =A0Thus, a > default value (in this case 0x7FFFFFFF) means no value has been > entered. =A0All code that uses any values should check for this no-value > and act accordingly, but of course not all the code actually does > that, and there are odd cases where the no-value value gets processed > as a valid value and then Bad Things Happen. > > I'm curious what the Ada approach to this issue would be, the issue > being to differentiate between valid and invalid values, and to catch > (compile time or run time) any manipulation of an invalid value as if > it were a valid value. I guess something like this: type T is range ...; type Opt_T (Is_Valid : Boolean :=3D False) is record case Is_Valid is when True =3D> Value : T; when False =3D> null; end case; end record; - Mark L