You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

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.

Non-Compliant Code Example

This non-compliant code example can fail because a copy of stdout is being used in the call to fputs().

#include <stdio.h>

int main(void) {
    FILE my_stdout = *(stdout);
    fputs("Hello, World!\n", &my_stdout);

    return 0;
}

Platform Specific Details

This non-compliant example does fails with an "access vilation" when compiled under Microsoft Visual Studio 2005 and run on an IA-32 platform.

Compliant Solution

In this compliant solution, the original FILE object is used in the call to fputs().

#include <stdio.h>

int main(void) {
    fputs("Hello, World!\n", stdout);
    return 0;
}

References

  • No labels