Article View: gnu.gcc.help
Article #42774Re: gcc fflush(stdin) problem
From: Maurizio Loreti
Date: Fri, 20 Oct 1995 00:00
Date: Fri, 20 Oct 1995 00:00
30 lines
2218 bytes
2218 bytes
In article <DGpBAs.62E@boss.cs.ohiou.edu>, deering@bobcat.ent.ohiou.edu (Paul Deering) writes:
>Hello, I am an instructor at Ohio Univsersity and teaching a C
>course for the College of Engineering and Technology.
>I am using 2.7.0 of gcc. I am trying to fflush(stdin)
>but it is not working properly.
fflush(stdin) is not defined by the language, and causes undefined
behaviour; the relevant quote from the comp.lang.c FAQ is:
----------------------------------------------------------------------
12.26: How can I flush pending input so that a user's typeahead isn't
read at the next prompt? Will fflush(stdin) work?
A: fflush() is defined only for output streams. Since its
definition of "flush" is to complete the writing of buffered
characters (not to discard them), discarding unread input would
not be an analogous meaning for fflush on input streams.
There is no standard way to discard unread characters from a
stdio input stream, nor would such a way be sufficient unread
characters can also accumulate in other, OS-level input buffers.
References: ANSI Sec. 4.9.5.2; ISO Sec. 7.9.5.2; H&S Sec. 15.2.
----------------------------------------------------------------------
I don't know how gcc reacts to fflush(stdin), but I definitely don't
want to use in my programs statements whose execution can cause
different behaviour with different compilers, or different versions of
the same compiler...
Maurizio Loreti http://mvxpd5.pd.infn.it/wwwcdf/mlo.html
Un. of Padova, Dept. of Physics - Padova, Italy loreti@padova.infn.it
Technical Details
Message-ID:
<DGqqGE.42t@news.cern.ch>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<DGpBAs.62E@boss.cs.ohiou.edu>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 11318c,ac805b42612e8e71,start X-Google-Attributes: gid11318c,public From: loreti@mxsld2.pd.infn.it (Maurizio Loreti) Subject: Re: gcc fflush(stdin) problem Date: 1995/10/20 Message-ID: <DGqqGE.42t@news.cern.ch> X-Deja-AN: 117854674 sender: news@news.cern.ch (USENET News System) x-nntp-posting-host: mxsld2.pd.infn.it references: <DGpBAs.62E@boss.cs.ohiou.edu> organization: I.N.F.N. Padova - CDF/CMS VAXcluster reply-to: loreti@mxsld2.pd.infn.it newsgroups: gnu.gcc.help