Ok to fclose stdin?

S

Steve

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.
 
E

Eric Sosman

Steve said:
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.
 
S

Steve

Eric said:
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.
 

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

Similar Threads


Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,905
Latest member
Kristy_Poole

Latest Threads

Top