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-Thread: 103376,a0833bbed8752e1f X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: variable length strings Date: Thu, 28 Oct 2004 10:14:19 +0200 Message-ID: <1ok9c1htwcrmd.dta4w50brarb.dlg@40tude.net> 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> <1098814048.280053@master.nyc.kbcfp.com> <10z8k19febkic.16ex86io5uvwi.dlg@40tude.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de wLONDGdfasr1vKJzl/8QSg5Pugk2HECjAV4fSMro2Kat5Q414= User-Agent: 40tude_Dialog/2.0.12.1 Xref: g2news1.google.com comp.lang.ada:5781 Date: 2004-10-28T10:14:19+02:00 List-Id: On 27 Oct 2004 18:38:29 +0200, Pascal Obry wrote: > "Dmitry A. Kazakov" writes: > >> But the existing Get_Line does not reaches the goal either. Normally it is >> used with the buffer allocated on the stack. So it is the stack again. > > That's wrong! > > procedure Get_Line(Item : out String; Last : out Natural); > > The buffer is bounded in this case, it's up to you to read a chunk of data > (using a small buffer on the stack) and do whatever is needed with it. So I > see not problem with the standard Get_Line. You (Get_Line) just push the problem to the user, who will write: declare Buffer : String (1..?); Length : Integer; begin Get_Line (Buffer, Length); 1) Buffer is on the stack. 2) Its upper bound is unknown except for very rare cases. The requirements usually as helpful as "it should work with reasonable files". Go figure out the upper bound! As for chunks of data, this is well another story. Note, if the parsing methods allow arbitrary splitting the lines <=> it can work with character stream <=> you need no Get_Line, the appropriate method is: procedure Get(Item : out Character); > I never said that you can't use > the stack, just that using a buggy Get_Line implementation as proposed here > could heat too much stack space and is therefore unsafe. I agree that it is a problem, but it is not the Get_Line's one. It is a more general language issue, which probably should be answered in the future. We cannot just dismiss T'Class, unconstrained containers etc. An ability to deal with them (on the stack) is quite important. It is also a question what compromises safety more: use of pointers or potential stack overflow. For large projects, I would say it is definitively pointers. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de