ストリームを 1 つの FILE *fp に書き込み、同時にストリームを別の fp にコピーしたいのですが、fprintf を 1 つ削除してデバッグ関数を作成するより良い方法はありますか?
const int logflag=1;
#define debug(args ...) if (logflag) { FILE *flog = fopen("test.log", "a+"); fprintf( flog, args); fclose(flog); } fprintf(stderr, args);
int main()
{
debug("test"); // writes test into both stderr and flog
debug("test2");
}