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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,48db656ff6b82a79 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-02-16 11:23:48 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!cyclone.bc.net!sjc70.webusenet.com!news.webusenet.com!newsfeed2.earthlink.net!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread2.prod.itd.earthlink.net.POSTED!not-for-mail Message-ID: <3E4FE52F.2060101@acm.org> From: Jeffrey Carter User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.0.0) Gecko/20020530 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Newbie, returning strings in Ada References: <87525c4f.0302160333.de26f1@posting.google.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Date: Sun, 16 Feb 2003 19:23:48 GMT NNTP-Posting-Host: 63.184.32.9 X-Complaints-To: abuse@earthlink.net X-Trace: newsread2.prod.itd.earthlink.net 1045423428 63.184.32.9 (Sun, 16 Feb 2003 11:23:48 PST) NNTP-Posting-Date: Sun, 16 Feb 2003 11:23:48 PST Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: archiver1.google.com comp.lang.ada:34157 Date: 2003-02-16T19:23:48+00:00 List-Id: Santiago A. wrote: > 2) This case works fine too: > > var U_Line:Unbounded_String; > .... > U_Line:=To_Unbounded_String(Get_Line(Sock)); > > > 3) This case fails > > var F_Line:string:="1234567890"; > ..... > F_Line:=Get_Line(Sock); This is not Ada. Perhaps you are using Pascal; "var" is not part of Ada's syntax. If you were using Ada, you might write declare F_Line : String := "1234567890"; begin F_Line := Get_Line (Sock); ... end; The assignment to F_Line will usually raise Constraint_Error. The only time this will not raise an exception is when Get_Line returns a String of length 10, or if you have run-time checks suppressed. I suggest you not suppress run-time checking. Using an Unbounded_String works because it's an abstraction that may hold a string of any length. An object of type String is always the same length. > Is there any problem in a function that returns a string with lenght 2 > into a variable string(10)? Yes. > > Must the returned string and the variable that will hold the result be > of the same length? Yes. However, you can store the result in an object created for that purpose: declare F_Line : [constant] String := Get_Line (Sock); begin ... end; If you leave off "constant", then you can modify the value in F_Line. If you don't do that, though, it's best to mark the object as a constant. -- Jeff Carter "If I could find a sheriff who so offends the citizens of Rock Ridge that his very appearance would drive them out of town ... but where would I find such a man? Why am I asking you?" Blazing Saddles