Using the value of a pointer to a ``++FILE++`` object after the associated file is closed is undefined behavior.


== Noncompliant Code Example

----
void fun() {
  FILE * pFile;
  pFile = fopen(fileName, "w");

  if (condition) {
    fclose(pFile);
    // ...
  }

  fclose(pFile); // Noncompliant, the file has already been closed
}
----


== Compliant Solution

----
void fun() {
  FILE * pFile;
  pFile = fopen(fileName, "w");

  if (condition) {
    // ...
  }

  fclose(pFile);
}
----


== See

* https://wiki.sei.cmu.edu/confluence/x/QdUxBQ[CERT, FIO46-C.] - Do not access a closed file


ifdef::env-github,rspecator-view[]
'''
== Comments And Links
(visible only on this page)

include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]
