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-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!news1.google.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!nntp.club.cc.cmu.edu!micro-heart-of-gold.mit.edu!newsswitch.lcs.mit.edu!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: What would be the Ada solution? Date: Fri, 04 Feb 2011 12:47:52 -0500 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <635897a9-13a6-409c-948d-37d93c5e1c29@glegroupsg2000goo.googlegroups.com> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls6.std.com 1296841673 30806 192.74.137.71 (4 Feb 2011 17:47:53 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Fri, 4 Feb 2011 17:47:53 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:sWgl2o0dkrDH/FU0Xn3Fn41Qu30= Xref: g2news2.google.com comp.lang.ada:17847 Date: 2011-02-04T12:47:52-05:00 List-Id: mockturtle writes: > 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. Yes. Or: type Valid_Values is range 0 .. 2**10 - 1; subtype Extended_Values is Valid_Values'Base range -1 .. Valid_Values'Last; The base range is guaranteed to contain -1, because base ranges are always symmetric about zero (usually with one extra negative value). But these solutions involve implicit run-time checks. Using two types instead of subtypes moves most of the checking to compile time. - Bob