Re: Complicated macro...




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)

.



Relevant Pages


Loading