[Courses] Re: [C] A clarification on fflush(stderr)

Anand R anand.r at cybertech.co.in
Wed Aug 7 12:01:12 EST 2002


Hi team,

	Just a small doubt. I have seen many flushing stderr in their code.
Why is it necessary to flush stderr?? A small code example below:

#include	"systype.h"
#include	<stdio.h>

#define	MAXHOSTNAMELEN	  64	/* max size of a host name */
#define	MAXLINE		 255	/* line length for error messages */
#define	MAXBUFF		2048	/* max buffer length */

/*
 * Debug macro, based on the traceflag.
 * Note that a daemon typically freopen()s stderr to another file
 * for debugging purposes.
 */

#define	DEBUG(fmt)		if (traceflag) { \
					fprintf(stderr, fmt); \
					fputc('\n', stderr); \
					fflush(stderr); \
				} else ;

#define	DEBUG1(fmt, arg1)	if (traceflag) { \
					fprintf(stderr, fmt, arg1); \
					fputc('\n', stderr); \
					fflush(stderr); \
				} else ;

#define	DEBUG2(fmt, arg1, arg2)	if (traceflag) { \
					fprintf(stderr, fmt, arg1, arg2); \
					fputc('\n', stderr); \
					fflush(stderr); \
				} else ;

#define	DEBUG3(fmt, arg1, arg2, arg3)	if (traceflag) { \
					fprintf(stderr, fmt, arg1, arg2,
arg3); \
					fputc('\n', stderr); \
					fflush(stderr); \
				} else ; >>>>>>>>>>>>>>>>>>>>>>>>>>>>

Thanks,
Andy



More information about the Courses mailing list