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,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-02-16 03:33:52 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: general@ciberpiula.net (Santiago A.) Newsgroups: comp.lang.ada Subject: Newbie, returning strings in Ada Date: 16 Feb 2003 03:33:52 -0800 Organization: http://groups.google.com/ Message-ID: <87525c4f.0302160333.de26f1@posting.google.com> NNTP-Posting-Host: 62.82.85.64 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1045395232 10071 127.0.0.1 (16 Feb 2003 11:33:52 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 16 Feb 2003 11:33:52 GMT Xref: archiver1.google.com comp.lang.ada:34149 Date: 2003-02-16T11:33:52+00:00 List-Id: Hello: I'm a newbie in Ada, and I'm trying to test AdaSockets. Using the example listener.adb", I try to read a line from a socket but the program has a strange behavior. After a little investigation I think it has little to do with sockets, I'm afraid it's about something I haven't understood about Ada strings. So I decided to to post it in ada group instead AddSockets developers, if it's not the case, sorry ;-) I use get_line function of AdaSockets, this reads character by character from the socket, and add them to a string, if the char is LF then returns. Everything works fine until It returns, then Depending upon how I call the function, the programa stops. This is the original procedure found in AdaSockets body: function Get_Line ( Socket : Socket_Fd'Class ) return String is Result : String (1 .. 1024); Index : Positive := Result'First; Char : Character; begin loop Char := Get_Char (Socket); if Char = Lf then return Result (1 .. Index - 1); elsif Char /= Cr then Result (Index) := Char; Index := Index + 1; if Index > Result'Last then return Result & Get_Line (Socket); end if; end if; end loop; end Get_Line; 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? By the way, I'm working with gnat-3.15p on Windows 2000. Thanks