home *** CD-ROM | disk | FTP | other *** search
- From: dbaum@camilla.East.Sun.COM (Derek Baum - Sun PC Distributed Systems)
- Newsgroups: comp.lang.c,comp.unix.wizards,alt.sources,comp.sources.d,misc.misc
- Subject: Re: #define DEBUG... (using printf for debugging)
- Message-ID: <1851@east.East.Sun.COM>
- Date: 8 May 90 12:29:45 GMT
-
- In article <1104@auto-trol.UUCP> robwah@auto-trol.UUCP (Robert Wahl) writes:
- >Writing "dprintf" is left as an exercise for the reader. Using assembly
- >language, it may be an easy thing to prepend stderr to the variable argument
- >list and then call "fprintf". Most likely, though, you will have to parse the
- >format string for the number and type of arguments in order to set up the
- >call to "fprintf". If so, you might as well do it all in C (which at least
- >is portable), and do your output in stages.
- >
-
- It is easy to write dprintf() using vfprintf() as follows:
-
- #include <stdarg.h>
-
- int dprintf(char *format, ...)
- {
- va_list ap;
-
- va_start(ap, format);
-
- fprintf(stderr, "debug: ");
- vfprintf(stderr, format, ap);
- }
-
- --
- Derek Baum consulting at:
- Sun Microsystems Internet: dbaum@East.Sun.COM
- (508)671-0456 UUCP: ...!sun!suneast!dbaum
-