Versions Compared

Key

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

According to the C Standard, Section subclause 7.21.3, paragraph 6 [ISO/IEC 9899:2011],

...

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

For example, this noncompliant example raises an "access violation" exception at runtime when compiled under Microsoft Visual Studio Express 2012 and run under Windows.

...

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

...

Bibliography

[ISO/IEC 9899:2011]Section Subclause 7.21.3, "Files"

 

...