Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The following non-compliant code opens the file log twice concurrentlywrite logs about the programs state at runtime.

Code Block
bgColor#ffcccc"
void do_stuff(void) {
  FILE* logfile = fopen("log", "a");
  
  /* Check for errors, write logs pertaining to do_stuff, etc. */
}

int main() {
  FILE* logfile = fopen("log", "a");

  /* Check for errors, write logs pertaining to main, etc. */

  do_stuff()

  /* ... */
}

However, it opens the file log twice simultaneously. As stated above, the result is implementation defined and dangerous.

Compliant Solution

In this compliant solution, a reference to the file pointer is passed around so that the file does not have to be opened twice separately.

...