Extent of the "as-if" rule

G

glen herrmannsfeldt

Barry Margolin wrote:

(snip regarding side effects of fopen())
But it may only be updated if you actually read something from the file;
the act of opening the file in read mode might not update it (consider a
file on an NFS server -- there's nothing in NFS that corresponds to
open() or close(), the server only sees the directory lookup and the
read/write operations).

There is an additional effect with NFS that I believe is system
dependent, and that is whether the last access time is updated
from the client clock or the server clock.

Of course, the C standard doesn't say anything about that, either.

-- glen
 
D

Douglas A. Gwyn

pete said:
A conforming implementation need not produce any output
nor accept any input during the execution of a program.

Strictly speaking, it needs to make the attempt or else
it hasn't implemented the semantics as specified. But
so much of file behavior is environment-dependent that
sanity in that department becomes more a "quality of
implementation" issue; i.e., the marketplace decides
whether an implementation can get away with constant
I/O failure. Odds are that no hosted implementation
would succeed without being able to perform I/O using
the most common kinds of file on a platform. There are
even implementations of C for embedded system that
manage to support file I/O one way or another (e.g.,
over the debugger console port).
 
P

pete

CBFalconer said:
pete wrote:
I would recommend the immediate return. Once the EOF has been
received something has gone wrong, and the string will not be
properly output. Any further 'hammering' may disturb the error
status, which in turn will prevent proper diagnostics.

Thank you.
 
P

Peter Nilsson

CBFalconer said:
I would recommend the immediate return.

So would I.
Once the EOF has been
received something has gone wrong,

[Assuming UCHAR_MAX <= INT_MAX.]
and the string will not be
properly output. Any further 'hammering' may disturb the error
status, which in turn will prevent proper diagnostics.

What 'error status' will be disturbed? Neither puts nor putchar can reset
the end-of-file or error indicator.

I'd argue the early return purely on the basis that that puts should
(IMHO)return EOF immediately an error is reported by fputc.
 
C

CBFalconer

Peter said:
What 'error status' will be disturbed? Neither puts nor putchar
can reset the end-of-file or error indicator.

But a subsequent error may be the result of the initial error.
There are no specifications about this AFAIK, and it is up to the
i/o system designer.
 
P

pete

CBFalconer said:
But a subsequent error may be the result of the initial error.
There are no specifications about this AFAIK, and it is up to the
i/o system designer.

There's a scene on The Simpsons where Bart joins the
Junior Campers and faints. Ned tells one of the kids to give
Bart mouth to mouth. At first contact, Bart wakes up screaming
and the kid says "Should I keep doing it?"
Stopping makes sense to me, but I don't see in the standard
what implies that the puts function can stop
before it gets to the end of the string.
However, if returning at the first hint of EOF, were the wrong thing
to do, I'm sure somebody else would have said something by now.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top