DEVCPP + rewind(stdin)

K

Keith Thompson

Kenneth Brody said:
On my system, rewind() says it also clears any error status, which is
something fseek() doesn't do.

I don't know if that's standard or not, however.

Yes, it is.

C99 7.19.9.5:

The rewind function sets the file position indicator for the
stream pointed to by stream to the beginning of the file. It is
equivalent to

(void)fseek(stream, 0L, SEEK_SET)

except that the error indicator for the stream is also cleared.
 
R

Richard Tobin

Keith Thompson said:
The rewind function sets the file position indicator for the
stream pointed to by stream to the beginning of the file. It is
equivalent to

(void)fseek(stream, 0L, SEEK_SET)

except that the error indicator for the stream is also cleared.

Is this a mistake? Perhaps the intention was that it should clear the
error indication *before* the fseek? Or that a successful call should
clear it (as with fseek and the end-of-file indication)? That would
make a lot more sense.

-- Richard
 
K

Keith Thompson

Is this a mistake? Perhaps the intention was that it should clear the
error indication *before* the fseek? Or that a successful call should
clear it (as with fseek and the end-of-file indication)? That would
make a lot more sense.

Yes, it would, but I think it was deliberate.

fseek() returns an int value that indicates whether it succeeded.
rewind() returns void. That can't have been accidental. The wording
is identical in the C90 standard. (Prior to that, rewind() would have
implicitly returned int; I don't know whether the result was
meaningful in pre-ANSI implementations.)

The Rationale says:

Resetting the end-of-file and error indicators was added to the
specification of rewind to make the specification more logically
consistent.

Perhaps this is a question for comp.std.c.
 
W

Walter Roberson

Keith Thompson said:
fseek() returns an int value that indicates whether it succeeded.
rewind() returns void. That can't have been accidental. The wording
is identical in the C90 standard. (Prior to that, rewind() would have
implicitly returned int; I don't know whether the result was
meaningful in pre-ANSI implementations.)

K&R2's description of rewind is:

void rewind(FILE *stream)
rewind(fp) is equivalent to fseek(fp,0L,SEEK_SET); clearerr(fp) .

That's pretty clear that the error is cleared even if the fseek() fails.
 
J

Jordan Abel

Yes, it would, but I think it was deliberate.

fseek() returns an int value that indicates whether it succeeded.
rewind() returns void. That can't have been accidental. The wording
is identical in the C90 standard. (Prior to that, rewind() would have
implicitly returned int; I don't know whether the result was
meaningful in pre-ANSI implementations.)

http://minnie.tuhs.org/UnixTree/V7/usr/src/libc/stdio/rew.c.html

If it was significant (it would be so by being the return value of
lseek, presumably), it was only so by accident.
The Rationale says:

Resetting the end-of-file and error indicators was added to the
specification of rewind to make the specification more logically
consistent.

Perhaps this is a question for comp.std.c.

Crossposted, but I suspect the reason is to clear any error which was
set before which is no longer relevant at the beginning of the file
(say, a write error due to no more space being available) Though I'd
wonder why fseek doesn't do the same thing for the same reason.
 

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

No members online now.

Forum statistics

Threads
474,183
Messages
2,570,967
Members
47,520
Latest member
KrisMacono

Latest Threads

Top