469,625 Members | 1,177 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,625 developers. It's quick & easy.

Ok to fclose stdin?


Is it allowed to fclose stdin?

Trying it here it seems to work ok, but it occurs to me that on some other
system the standard library might call fclose(stdin) during its clean up,
and calling fclose twice (on normal streams at least) gives undefined
behaviour.
Nov 13 '05 #1
2 4405
Steve wrote:

Is it allowed to fclose stdin?

Trying it here it seems to work ok, but it occurs to me that on some other
system the standard library might call fclose(stdin) during its clean up,
and calling fclose twice (on normal streams at least) gives undefined
behaviour.


The Standard doesn't appear to prohibit closing stdin
(or stdout and stderr, for that matter, except that the
behavior of perror() and assert() becomes problematic if
stderr is closed).

The Standard also doesn't say that stdin/out/err get
closed during program termination; it says that *all* open
streams get closed, and doesn't make a special case for
these three. Perhaps that's a suggestive omission.

--
Er*********@sun.com
Nov 13 '05 #2
Eric Sosman wrote:
Steve wrote:
Is it allowed to fclose stdin?


The Standard also doesn't say that stdin/out/err get
closed during program termination; it says that *all* open
streams get closed, and doesn't make a special case for
these three. Perhaps that's a suggestive omission.


Ah yes you're right, it doesn't say stdin/out/err get closed.

Thanks.

Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by viza | last post: by
11 posts views Thread by Marcus Jacobs | last post: by
6 posts views Thread by ccdrbrg | last post: by
20 posts views Thread by David Mathog | last post: by
53 posts views Thread by Bartc | last post: by
3 posts views Thread by wrenashe | last post: by
reply views Thread by Gabriel Genellina | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.