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,8623fab5750cd6aa X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news.glorb.com!wn12feed!worldnet.att.net!bgtnsc04-news.ops.worldnet.att.net.POSTED!53ab2750!not-for-mail From: Dave Thompson Newsgroups: comp.lang.ada Subject: Re: Ada BIND was: Improving Ada's image - Was: 7E7 Flight Controls Electronics Message-ID: References: X-Newsreader: Forte Agent 1.93/32.576 English (American) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Thu, 01 Jul 2004 04:08:50 GMT NNTP-Posting-Host: 12.75.191.75 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc04-news.ops.worldnet.att.net 1088654930 12.75.191.75 (Thu, 01 Jul 2004 04:08:50 GMT) NNTP-Posting-Date: Thu, 01 Jul 2004 04:08:50 GMT Organization: AT&T Worldnet Xref: g2news1.google.com comp.lang.ada:2017 Date: 2004-07-01T04:08:50+00:00 List-Id: On Tue, 15 Jun 2004 12:40:46 +1000, Brian May wrote: > >>>>> "Alexander" == Alexander E Kopilovich writes: > > Alexander> Well, for C, that is for fread and fgets I would say > Alexander> that although these functions indeed have maximum > Alexander> amount of bytes to be read onto a buffer as a > Alexander> parameter, but: > > Alexander> 1) this maximum, if not computed from "preliminary > Alexander> read", is usually set manually, it does not computed > Alexander> automatically from the length of the buffer used in > Alexander> that fread/fgets; therefore there is an obsvious > Alexander> possibility of programmer's mistake, which will not be > Alexander> noticed by compiler; > Not fully automatic. You can and often should do e.g. fgets (buff, sizeof buff, in_file) -- but this is !silently! wrong if buff is a function=routine parameter/formal declared as a char array -- but due to C rules, actually a pointer -- rather than a local or static/global variable. You can write (and use) a macro that automatically supplies the sizeof and even uses (unaesthetically) tricky code to diagnose nonarrays; or in C++ a clearer and more elegant inlined template that supplies the size and diagnoses nonarray -- but in C++ it's more idiomatic to use the stream >> operators instead, which can among other things read into std::string which is dynamic comparable to Unbounded_String. > ...not to mention older functions that don't support a string length > (eg. sprintf). Some have better versions (eg. snprintf or asprintf), > but such functions are often non-standard and non-portable extensions. > snprintf is standard as of C99, although not fully compatible (specifically return value) with some(?) pre-C99 extension versions. - David.Thompson1 at worldnet.att.net