 
                            ...
| Code Block | ||
|---|---|---|
| 
 | ||
| 
FILE *fptr = NULL;
int c = 'a';
while (c <= 'z') {
  putc(c++, fptr ? fptr : (fptr = fopen(file_name, "w"));
}
 | 
It is possible for the putc macro to instantiate its file descriptor argument 2 or more times. This might still seem safe, as the ?: operator ostensibly prevents multiple calls to fopen, there is no guarentee that these would happen in distinct sequence points. So this could would also violate EXP30-C. Do not depend on order of evaluation between sequence points.
Compliant Solution: putc()
In the compliant solution, c++ is no longer an the file descriptor argument to putc() no longer has side effects.
| Code Block | ||
|---|---|---|
| 
 | ||
| 
FILE *fptr = fopen(file_name, "w");
if (fptr == NULL) {
  /* Handle Error */
}
int c = 'a';
while (c <= 'z') {
  putc(c++, fptr);
}
 | 
...