home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / c / 16634 < prev    next >
Encoding:
Internet Message Format  |  1992-11-17  |  2.1 KB

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