
...
Code Block | ||
---|---|---|
| ||
void do_stuff(void) { FILE *logfile = fopen("log", "a"); /* Check for errors, write logs pertaining to * do_stuff(), etc. */ } int main(void) { FILE *logfile = fopen("log", "a"); /* Check for errors, write logs pertaining to * main(), etc. */ FILE *logfile = fopen("log", "a"); do_stuff(); /* ... */ } |
However, the file log
is opened twice simultaneously. The result is implementation-defined and potentially dangerous.
...
Code Block | ||
---|---|---|
| ||
void do_stuff(FILE *logfile) {
/* Check for errors, write logs pertaining to
* do_stuff, etc. */
}
int main(void) {
FILE *logfile = fopen("log", "a");
/* Check for errors, write logs pertaining to main, etc. */
do_stuff(logfile);
/* ... */
}
|
...