Article View: comp.std.c
Article #4810Re: fflush: ANSI C v. POSIX.1
From: Jerry Coffin
Date: Fri, 16 Feb 1996 19:17
Date: Fri, 16 Feb 1996 19:17
39 lines
2506 bytes
2506 bytes
cowen@clark.edu (James M. Cowen) wrote: [ ... ] >In short, I'm confused, can someone clarify how one would use fflush() >in a portable fashion ... no that's not what I want to ask. Don't use >fflush() on a read/update stream, that seems obvious given ANSI C, but >it "works" on POSIX.1 systems, but POSIX.1 indicates it accepts the >ANSI C standard, but ... I hope you get the drift of my question. >In passing, I'm teaching a class using W. Richard Stevens book, "Advanced >Programming in a Unix Environment", and was unable to advance a satisfactory >explanation of fflush() with respect to ANSI C and POSIX.1. Indeed, my >response, "interesting" was not only unsatisfactory to my students, it >was inappropriate. Everything here sounds perfectly reasonable to me. POSIX.1 includes the ISO standard for C, therefore everything that's defined in the C standard is also defined in POSIX. However, POSIX also defines quite a bit more, that is NOT defined in the C standard. In many cases the new definitions are embodied in functions that are not defined in the C standard at all, and typically using headers that are not defined in the C standard either. However, some of the behavior specified by POSIX involves defining behavior of functions that are in the C standard, but which are more restrictive of the functions (and therefore less restrictive on calling code) than the C standard. For instance, the C standard mandates the presence of `errno' and specifies its purpose, but has only a minimal definition of how its value may be affected by standard functions. POSIX is more restrictive in specifying considerably more about what functions will set errno to particular values and under what circumstances they will do so. Likewise, with fflush, the C standard simply doesn't define the results unless it's applied to a stream opened for writing, or opened for update and for which the last operation was a write. POSIX apparently restricts the function further, by saying that it must provide a defined result when applied to a stream opened for reading, or from which reading has been done.
Technical Details
Message-ID:
<4g2got$2s2@natasha.rmii.com>Path:
arc1-ca.pugleaf.net!news.rmii.com!usenetReferences:
<4frf81$gmn@clark.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.rmii.com!usenet From: jcoffin@rmii.com (Jerry Coffin) Newsgroups: comp.std.c Subject: Re: fflush: ANSI C v. POSIX.1 Date: Fri, 16 Feb 1996 19:17:04 GMT Organization: TAEUS Message-ID: <4g2got$2s2@natasha.rmii.com> References: <4frf81$gmn@clark.edu> NNTP-Posting-Host: slip22160.rmii.com X-Newsreader: Forte Free Agent 1.0.82