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,1b6f0735bc6de58e X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!dr5g2000vbb.googlegroups.com!not-for-mail From: tonyg Newsgroups: comp.lang.ada Subject: Re: index check failure - constraint error Date: Fri, 1 Apr 2011 15:16:28 -0700 (PDT) Organization: http://groups.google.com Message-ID: <8fc6d308-c548-4efc-9f5d-aa1bc37742d8@dr5g2000vbb.googlegroups.com> References: NNTP-Posting-Host: 82.46.232.121 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1301696188 22172 127.0.0.1 (1 Apr 2011 22:16:28 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 1 Apr 2011 22:16:28 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: dr5g2000vbb.googlegroups.com; posting-host=82.46.232.121; posting-account=28F2IwkAAACL1Z5nRC-dE7zuvWdbWC7P User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-GB; rv:1.9.2.16) Gecko/20110319 Firefox/3.6.16 GTB7.1 ( .NET CLR 3.5.30729; .NET4.0E) GTBA,gzip(gfe) Xref: g2news1.google.com comp.lang.ada:18671 Date: 2011-04-01T15:16:28-07:00 List-Id: On Apr 1, 6:39=A0pm, Jeffrey Carter wrote: > On 04/01/2011 03:53 AM, tonyg wrote: > > > > > I'm getting a constraint error and I cannot see why... > > In addition to the Get procedures from Ada.Text_IO.*_IO (Integer_IO, Modu= lar_IO, > Float_IO, and Fixed_IO), there's also 'Value to convert a String > representation to a numeric type. 'Value is less flexible than Get, but i= s a > function rather than a procedure. Both will handle values like "1E4". > > As others have pointed out, and as I noticed as soon as I looked at your = code, > not all Strings have a lower bound of 1, and that is probably why this ra= ises > Constraint_Error. If you showed the calling code we could explain it more= fully. > Using 'Range avoids this; that's why it exists. > > In addition, I would comment that The_String'Length cannot be negative, s= o > String_Length should be Natural rather than Integer to indicate this, and= since > its value never changes, it should be a constant: > > String_Length : constant Natural :=3D The_String'Length; > > (Personally, I'd call this > > function Value (Image : in String) return Integer; > > and just use Image'Length.) > > There's no need for the "if" checking the length; the loop will execute z= ero > times if the String is null, giving a result of zero (which I think is in= correct). > > Finally, I think you have a logic error. Given input of "123" with subtyp= e > String (1 .. 3), it returns > > 1 * 10 ** 0 + 2 * 10 ** 1 + 3 * 10 ** 2 /=3D 123. > > -- > Jeff Carter > "Saving keystrokes is the job of the text editor, > not the programming language." > Preben Randhol > 64 It so so does :) Thanks for that Preben. I hadn't got that far to discover the godzilla sized error that would of created. Thanks as well for the help off everyone else.