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=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,8623fab5750cd6aa X-Google-Attributes: gid103376,public Path: g2news1.google.com!news2.google.com!proxad.net!freenix!enst.fr!melchior!cuivre.fr.eu.org!melchior.frmug.org!not-for-mail From: "Alexander E. Kopilovich" Newsgroups: comp.lang.ada Subject: Re: Ada BIND was: Improving Ada's image - Was: 7E7 Flight Controls Electronics Date: Tue, 15 Jun 2004 04:02:16 +0400 (MSD) Organization: Cuivre, Argent, Or Message-ID: References: NNTP-Posting-Host: lovelace.ada-france.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: melchior.cuivre.fr.eu.org 1087258143 67299 212.85.156.195 (15 Jun 2004 00:09:03 GMT) X-Complaints-To: usenet@melchior.cuivre.fr.eu.org NNTP-Posting-Date: Tue, 15 Jun 2004 00:09:03 +0000 (UTC) To: comp.lang.ada@ada-france.org Return-Path: In-Reply-To: ; from Hyman Rosen at Mon, 14 Jun 2004 02:09:36 GMT X-Mailer: Mail/@ [v2.44 MSDOS] X-Virus-Scanned: by amavisd-new-20030616-p7 (Debian) at ada-france.org X-BeenThere: comp.lang.ada@ada-france.org X-Mailman-Version: 2.1.4 Precedence: list List-Id: "Gateway to the comp.lang.ada Usenet newsgroup" List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Xref: g2news1.google.com comp.lang.ada:1488 Date: 2004-06-15T04:02:16+04:00 Hyman Rosen wrote: > > Check the length of the string to be read, then read either that > > number of characters or the maximum buffer size. Of course, this means > > in many cases you have to read the string twice while Ada allows you to > > read it once. (Ask for N characters and get a count of how many you get.) > > Huh? fread, fgets, istream.getline, istream.read are all ways of > reading up to a pre-determined amount of data into a buffer in C > and C++. In no case does the string need to be read twice. > What a bizarre claim! Well, for C, that is for fread and fgets I would say that although these functions indeed have maximum amount of bytes to be read onto a buffer as a parameter, but: 1) this maximum, if not computed from "preliminary read", is usually set manually, it does not computed automatically from the length of the buffer used in that fread/fgets; therefore there is an obsvious possibility of programmer's mistake, which will not be noticed by compiler; 2) sometimes there is no reasonable estimate for *guaranteed* maximum of a string to be read, and therefore the length of the string can be greater than already allocated buffer; reading a string in chunks can be inconvenient for some reasons, and thus that double reading (first pass for determining the length of string, then allocating the buffer, and then second pass with filling the buffer). So I find that claim far from bizarre, but rather practical. (Certainly in C++ it is possible to coordinate reading with the buffer size automatically, so I don't speak about C++ here.) Alexander Kopilovich aek@vib.usr.pu.ru Saint-Petersburg Russia