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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,a0833bbed8752e1f X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsmm00.sul.t-online.de!t-online.de!news.t-online.com!not-for-mail From: Martin Krischik Newsgroups: comp.lang.ada Subject: Re: variable lenght strings Date: Tue, 26 Oct 2004 20:13:56 +0200 Organization: AdaCL Message-ID: <1845042.MQgRItqYm2@linux1.krischik.com> References: <1861614.TWv5A9FgVL@linux1.krischik.com> <4178e979_1@baen1673807.greenlnk.net> <1195374.UMjBCk7lO1@linux1.krischik.com> <1154613.ipZcUgduzp@linux1.krischik.com> <1174011.lJ1dcgRM3Q@linux1.krischik.com> Reply-To: krischik@users.sourceforge.net Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 8Bit X-Trace: news.t-online.com 1098814636 00 29121 cPUtXLMJilTT9ru 041026 18:17:16 X-Complaints-To: usenet-abuse@t-online.de X-ID: E6oEWkZVZePeYUGSnJtEWd1orB1GXSVNDoYQJAZ6bAbKGbIQXc8fk- User-Agent: KNode/0.8.0 Xref: g2news1.google.com comp.lang.ada:5732 Date: 2004-10-26T20:13:56+02:00 List-Id: Pascal Obry wrote: > > Martin Krischik writes: > >> function�Get_Line�( >> File�:�in�IO.File_Type) >> return >> String >> is >> Buffer�:�String�(1�..�BufferSize); >> Last���:�Natural; >> begin >> IO.Get_Line�( >> File�=>�File, >> Item�=>�Buffer, >> Last�=>�Last); >> >> if�Last�<�Buffer'Last�then >> return�Buffer�(1�..�Last); >> elsif�IO.End_Of_File�(File)�then >> return�Buffer; >> else >> return�Buffer�&�Get_Line�(File); > ^^^^^^^^^^^^^^^^^^^^^^^^^^ > > This kind of recursivity is very dangerous and could cause a stack > overflow. It is better to use a non recursive version and to store the > result into an Unbounded_String for example. In fact I have got an non recursive version returning an Unbounded_String as well: ���function�Get_Line�( ������File�:�in�IO.File_Type) ���return ������S_U.Unbounded_String ���is ������Retval�:�S_U.Unbounded_String�:=�S_U.Null_Unbounded_String; ������Item���:�String�(1�..�BufferSize); ������Last���:�Natural; ���begin ������GetWholeLine�: ������loop ���������IO.Get_Line�( ������������File�=>�File, ������������Item�=>�Item, ������������Last�=>�Last); ���������S_U.Append�( ������������Source���=>�Retval, ������������New_Item�=>�Item�(1�..�Last)); ���������exit�GetWholeLine�when�Last�<�Item'Last ����������������������or���IO.End_Of_File�(File); ������end�loop�GetWholeLine; ������return�Retval; ���end�Get_Line; With Regards Martin -- mailto://krischik@users.sourceforge.net http://www.ada.krischik.com