The address of the FILE object used to control a stream may be significant; a copy of a FILE object need not serve in place of the original. Consequently, do not use a copy of a FILE object in any input/output operations.
...
Noncompliant Code Example
This non-compliant noncompliant code example can fail because a copy of stdout is being used in the call to fputs().
| Code Block | ||
|---|---|---|
| ||
int main(void) {
FILE my_stdout = *(stdout);
if (fputs("Hello, World!\n", &my_stdout) == EOF) {
/* Handle Error */
}
return 0;
}
|
For example, this non-compliant noncompliant example fails with an "access violation" when compiled under Microsoft Visual Studio 2005 and run under Windows.
...