Versions Compared

Key

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

...

Code Block
bgColor#ffcccc
FILE *fptr = NULL;
int c = 'a';
while (c <= 'z') {
  if (putc(c++, fptr ? fptr : 
       (fptr = fopen(file_name, "w")) == EOF) 
  {
    /* Handle Error */
  }
}

If the putc() macro evaluates its stream argument multiple times, this might still seem safe, as the ?: operator ostensibly prevents multiple calls to fopen(). However, there is no guarantee that these would happen in distinct sequence points. Consequently this code also violates EXP30-C. Do not depend on order of evaluation between sequence points.

...