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,1b6f0735bc6de58e X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!feeder.news-service.com!feeder.news-service.com!94.75.214.39.MISMATCH!aioe.org!news.tornevall.net!.POSTED!not-for-mail From: Jeffrey Carter Newsgroups: comp.lang.ada Subject: Re: index check failure - constraint error Date: Fri, 01 Apr 2011 10:39:44 -0700 Organization: TornevallNET - http://news.tornevall.net Message-ID: References: NNTP-Posting-Host: d8afbc8c0d447126b0aa69fc9ddede7e Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: 536c4d73c5c0a1fdbd822e7dd7f6e7e9 X-Complaints-To: abuse@tornevall.net User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.14) Gecko/20110223 Thunderbird/3.1.8 X-Complaints-Language: Spoken language is english or swedish - NOT ITALIAN, FRENCH, GERMAN OR ANY OTHER LANGUAGE! In-Reply-To: X-UserIDNumber: 1738 X-Validate-Post: http://news.tornevall.net/validate.php?trace=536c4d73c5c0a1fdbd822e7dd7f6e7e9 X-Complaints-Italiano: Non abbiamo padronanza della lingua italiana - se mandate una email scrivete solo in Inglese, grazie X-Posting-User: 0243687135df8c4b260dd4a9a93c79bd Xref: g2news1.google.com comp.lang.ada:18670 Date: 2011-04-01T10:39:44-07:00 List-Id: 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, Modular_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 is 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 raises 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, so 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 := 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 zero times if the String is null, giving a result of zero (which I think is incorrect). Finally, I think you have a logic error. Given input of "123" with subtype String (1 .. 3), it returns 1 * 10 ** 0 + 2 * 10 ** 1 + 3 * 10 ** 2 /= 123. -- Jeff Carter "Saving keystrokes is the job of the text editor, not the programming language." Preben Randhol 64