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.2 required=5.0 tests=BAYES_00,FROM_LOCAL_HEX, FROM_STARTS_WITH_NUMS autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,146ef816afa699d1 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.46.193 with SMTP id x1mr20739560pbm.7.1318760125886; Sun, 16 Oct 2011 03:15:25 -0700 (PDT) Path: d5ni15761pbc.0!nntp.google.com!news2.google.com!news4.google.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "Vinzent Hoefler" <0439279208b62c95f1880bf0f8776eeb@t-domaingrabbing.de> Newsgroups: comp.lang.ada Subject: Re: Length of unbounded_string. Date: Sun, 16 Oct 2011 12:14:37 +0200 Message-ID: References: <4e9a9a6d$0$3238$703f8584@news.kpn.nl> Mime-Version: 1.0 X-Trace: individual.net nOklnzTvm3DY/r/k3rD6AAbffTaYGtmsevviSbI0UFJ2hk+MAA Cancel-Lock: sha1:b1NV4FzUgrz3QQlyHHDLYOiTIgM= User-Agent: Opera Mail/11.51 (Win32) Xref: news2.google.com comp.lang.ada:13971 Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Date: 2011-10-16T12:14:37+02:00 List-Id: ldries46 wrote: > In my program I use unbounded_string str > > I want to change the last character of the string using the program lines > > 2205 len := Length(str); > 2206 Replace_Slice(str, len, len, "G"); This seems correct to me. Although I am not sure, where ARM A4.3(74.1/1) would lead us here. ;) > Then I get the following message printed in my exception part of the program > > Error type : CONSTRAINT_ERROR > In phase : Step 1 > in function : Continuation > Error info : trans2ada.adb:2206 range check failed > > file line nr : 1 > Original line : /* GtkPrintJob > Next line : * Copyright (C) 2006 John (J5) Palmieri > > In this print out the Original line represents "str". > > Is there a problem with the Length function or do I interpret something > wrong? Well, I can't reproduce the problem here. Test code was: -- 8< -- X := Ada.Strings.Unbounded.To_Unbounded_String ("ABCD"); Y := Ada.Strings.Unbounded.Length (X); Ada.Strings.Unbounded.Replace_Slice (Source => X, Low => Y, High => Y, By => "Z"); Ada.Text_IO.Put_Line (Ada.Strings.Unbounded.To_String (X)); -- 8< -- It correctly prints "ABCZ". Same compiler version, so it seems something is wrong in your part of the code. First thing that comes to mind is that maybe the string in question does not have a lower bound of 1, but that's close to impossible with Unbounded_String. Another idea: Maybe, the string's last character is a null character and somethings gets garbled on the way between the C- and the Ada-world? Vinzent. -- f u cn rd ths, u cn gt a gd jb n cmptr prgrmmng.