Versions Compared

Key

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

Do not invoke getc() or putc() or their wide-character analogues getwc() and putwc() with stream arguments that have side effects.  The stream arguments to these macros may be evaluated more than once if these functions are implemented as unsafe macros. See PRE31-C. Do not perform Avoid side effects in arguments to unsafe macros for more information.

This rule does not apply to the character argument in putc() or the wide-character argument in putwc() which is guaranteed to be evaluated exactly once.

...

If the putc() macro evaluates its stream argument multiple times, this might still seem safe, as the ternary conditional expression ostensibly prevents multiple calls to fopen(). However, there is no guarantee that these calls would happen in distinct sequence points. Consequently, this code also violates EXP30-C. Do not depend on the order of evaluation for side effects.  This code also violates ERR33-C. Detect and handle standard library errors because it fails to check the return value from fopen().

...

 

...

Image Modified Image Modified