home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!ukma!darwin.sura.net!sgiblab!munnari.oz.au!goanna!ok
- From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe)
- Newsgroups: comp.lang.c
- Subject: Re: strange things with gcc
- Message-ID: <15984@goanna.cs.rmit.oz.au>
- Date: 17 Nov 92 04:46:40 GMT
- References: <9232201.24197@mulga.cs.mu.OZ.AU>
- Organization: Comp Sci, RMIT, Melbourne, Australia
- Lines: 37
-
- In article <9232201.24197@mulga.cs.mu.OZ.AU>, carl@montebello.ecom.unimelb.EDU.AU (Carl Brewer) writes:
- > I've had some funny problems with gcc on SunOS 4.1.2 of late, it doesn't
- > seem to handle fflush(stdin) very well (ie not at all).
-
- The standard does not require a C compiler to do anything with fflush(stdin).
- Calling fflush(stdin) may, as the saying goes, cause demons to fly out of
- your nose. Chris Torek's implementation quietly does nothing when you
- fflush() a file that is not in write mode.
-
- > my code works fine compiled under acc (SunOS 4.1.2), and microsoft QuickC
- > on a 386 PC. The relevant function is even straight from a book ...
-
- Please tell us what the book is so that we will know never to buy it.
-
-
- Since you explicitly mentioned SunOS 4.1.2, why didn't you check the on-line
- manual? It says
-
- fflush() writes any unwritten data for an output stream or
- an update stream in which the most recent operation was not
- input to be delivered to the host environment to the file;
- otherwise it is ignored. The named stream remains open.
-
- That is the "BSD" interface. The standard requires no more than that.
- If you keep on reading, you find under SYSTEM V DESCRIPTION that the
- System V version will discard unread input from an input stream.
-
- So the answer is simple: make sure that your program is linked with the
- System V stdio. How do you do that? It is very clearly described in the
- SunOS documentation. Check LD_LIBRARY_PATH in the manual page for ld(1).
- (Hint: there is a /usr/5lib.)
-
- If what you _really_ want is to flush buffered input from the terminal,
- then beware: there may be input buffered by the operating system that
- stdio doesn't happen to have read yet. Check the function tcflush() in
- the "termios" manual page; you'll need that _as well as_ fflush(stdin).
-
-