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.7 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM,REPLYTO_WITHOUT_TO_CC 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-7-bit Path: g2news2.google.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: mockturtle Newsgroups: comp.lang.ada Subject: Re: What would be the Ada solution? Date: Fri, 4 Feb 2011 09:14:10 -0800 (PST) Organization: http://groups.google.com Message-ID: <635897a9-13a6-409c-948d-37d93c5e1c29@glegroupsg2000goo.googlegroups.com> Reply-To: comp.lang.ada@googlegroups.com NNTP-Posting-Host: 158.110.27.77 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1296839650 27900 127.0.0.1 (4 Feb 2011 17:14:10 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 4 Feb 2011 17:14:10 +0000 (UTC) In-Reply-To: <0aa67233-4210-483b-b35c-8e872f87cb8f@r21g2000yqd.googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=158.110.27.77; posting-account=9fwclgkAAAD6oQ5usUYhee1l39geVY99 User-Agent: G2/1.0 Xref: g2news2.google.com comp.lang.ada:17842 Date: 2011-02-04T09:14:10-08:00 List-Id: On Friday, February 4, 2011 5:33:57 PM UTC+1, 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. Thus, a > default value (in this case 0x7FFFFFFF) means no value has been > entered. All 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. A solution that I saw used somewhere type Extended_Values is new integer range -1 .. 1023; subtype Valid_Values is Extended_Values range Extended_Values'first + 1 .. Extended_values'last; No_Value : constant Extended_Values := Extended_Values'first; A variable that should always have a valid value is declared of type Valid_Values and you should get an exception when you try to assign No_Value to it.