Versions Compared

Key

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

...

Code Block
bgColor#FFCCCC
langc
#include <stdio.h>
 
int main(void) {
  FILE my_stdout = *stdout;
  if (fputs("Hello, World!\n", &my_stdout) == EOF) {
    /* Handle error */
  }
  return 0;
}

This When compiled under Microsoft Visual Studio 2013 and run on Windows, this noncompliant example raises results in an "access violation" exception at runtime when compiled under Microsoft Visual Studio 2013 and run under Windows.

Compliant Solution

In this compliant solution, a copy of the stdout pointer to the FILE object is used in the call to fputs():

...

Related Guidelines

...