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 03:59:52 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!kibo.news.demon.net!news.demon.co.uk!demon!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Newbie, returning strings in Ada Date: 16 Feb 2003 11:58:44 +0000 Organization: Pushface Sender: simon@smaug.pushface.org Message-ID: References: <87525c4f.0302160333.de26f1@posting.google.com> NNTP-Posting-Host: pogner.demon.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: news.demon.co.uk 1045396791 8156 62.49.19.209 (16 Feb 2003 11:59:51 GMT) X-Complaints-To: abuse@demon.net NNTP-Posting-Date: Sun, 16 Feb 2003 11:59:51 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.1 Xref: archiver1.google.com comp.lang.ada:34150 Date: 2003-02-16T11:58:44+00:00 List-Id: general@ciberpiula.net (Santiago A.) writes: > 1) This case works fine: > Put_Line (Sock, get_line(Socket) ); > > where put_line spec is: > > procedure Put_Line (Socket : in Socket_FD'Class; > Str : in String) > > 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); > > I type two characters in the client side and press enter. Everything > seems to work fine, the server reads the first character, reads the > second,reads the LF, enters in the return sentence and... never > returns to the caller. > > Is there any problem in a function that returns a string with lenght 2 > into a variable string(10)? > > Must the returned string and the variable that will hold the result be > of the same length? I don't think you can have actually written var F_Line:string:="1234567890"; !!! Anyway, you are quite right, the returned string and the variable that will hold the result must be of the same length. Fortunately you can write loop declare f_line : constant string := get_line (sock); begin -- use f_line because each time you enter the declare block the compiler creates a new f_line of the length required to hold the actual string returned by this particular call to get_line. (the "constant" is just a programming style thing, declare things constant if you don't need them to be variables).