The behavior of a program is undefined when it uses the value of a pointer to a FILE
object after the associated file is closed (see undefined behavior 148.) Programs that close the standard streams (especially stdout
but also stderr
and stdin
) must be careful not to use the stream objects in subsequent function calls, particularly those that implicitly operate on such objects (such as printf()
, perror()
, and getc()
).
This rule can be generalized to other representations of files, such as an int
representing a POSIX file descriptor that has been passed to close()
..
Noncompliant Code Example
...