I had a situation in a C program, which contained hundreds of calls to "fprintf (stdout, ...", where I needed to flush stdout immediately after any stream was sent there. More specifically, I needed to add the command "fflush(stdout);" after every command that started with: fprintf(stdout fprintf (stdout fprintf( stdout fprintf ( stdout fprintf ( stdout etc. I wound up doing this manually (took about 30 minutes), but I later thought that I could have defined a macro to take care of this substitution. However, I couldn't even begin to think of the definition needed to handle every variable length fprintf call. Any ideas? Thanks.
No Such Luck wrote: I had a situation in a C program, which contained hundreds of calls to "fprintf (stdout, ...", where I needed to flush stdout immediately after any stream was sent there. More specifically, I needed to add the command "fflush(stdout);" after every command that started with: fprintf(stdout Are you familiar with variadic macros? In C99 you could do something like #define print_it(file_ptr, format, ...) do \ if (fprintf(file_ptr, format, ##__VA_ARGS__ ) == 0) fflush(file_ptr); /* else... handle the error if you like */ while(0)