Article View: comp.std.c
Article #3709Re: gets() and getchar
From: Thomas Koenig
Date: Fri, 11 Aug 1995 22:23
Date: Fri, 11 Aug 1995 22:23
35 lines
2056 bytes
2056 bytes
In comp.std.c, wirzeniu@cc.Helsinki.FI (Lars Wirzenius) wrote:
>The crucial distinction between strcpy and gets is that it is _possible_
>to check whether the call will succeed before it is made; with gets this
>is not possible. (Getting the check wrong is similar to getting the
>length wrong for fgets. This can't be easily fixed; anyone design a
>language that makes it impossible to make errors?)
Let's call it "Useless". It has one syntactically correct program
(an empty source file), which produces no output. Anything else
is undefined behaviour :-)
Seriously, this kind of error (array or string overrun) can be
avoided by array bounds checking.
Question: with modern optimization techniques, especially
strength reduction and invariant code moving, how much of
an overhead is array bounds checking?
If, for example, I have (Fortran as an example ;-)
REAL A(10,10),B(10,10),C(10,10)
DO 10 J=1,N
DO 20 I=1,N
A(I,J) = B(I,J) * C(J,I)
20 CONTINUE
10 CONTINUE
I see no reason why a compiler should insert more than one or
two checks at runtime there. However, I don't know how well
current compilers support this.
--
Thomas König, Thomas.Koenig@ciw.uni-karlsruhe.de, ig25@dkauni2.bitnet.
The joy of engineering is to find a straight line on a double
logarithmic diagram.
Technical Details
Message-ID:
<40gl8j$ak2@fg70.rz.uni-karlsruhe.de>Path:
arc1-ca.pugleaf.net!rz.uni-karlsruhe.de!not-for-mailReferences:
<40bqih$bft@caip.rutgers.edu> <40fn05$686@kruuna.helsinki.fi> <40g2cl$co7@tools.near.net> <40gbau$kh5@kruuna.helsinki.fi>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!rz.uni-karlsruhe.de!not-for-mail From: ig25@fg70.rz.uni-karlsruhe.de (Thomas Koenig) Newsgroups: comp.std.c,comp.lang.misc Subject: Re: gets() and getchar Followup-To: comp.lang.misc Date: 12 Aug 1995 00:23:15 +0200 Organization: Universität Karlsruhe (TH), Germany Message-ID: <40gl8j$ak2@fg70.rz.uni-karlsruhe.de> References: <40bqih$bft@caip.rutgers.edu> <40fn05$686@kruuna.helsinki.fi> <40g2cl$co7@tools.near.net> <40gbau$kh5@kruuna.helsinki.fi> Reply-To: Thomas.Koenig@ciw.uni-karlsruhe.de NNTP-Posting-Host: fg70.rz.uni-karlsruhe.de Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit NNTP-Posting-User: ig25