home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1345 < prev    next >
Encoding:
Internet Message Format  |  1990-12-28  |  1.1 KB

  1. From: dbaum@camilla.East.Sun.COM (Derek Baum - Sun PC Distributed Systems)
  2. Newsgroups: comp.lang.c,comp.unix.wizards,alt.sources,comp.sources.d,misc.misc
  3. Subject: Re: #define DEBUG... (using printf for debugging)
  4. Message-ID: <1851@east.East.Sun.COM>
  5. Date: 8 May 90 12:29:45 GMT
  6.  
  7. In article <1104@auto-trol.UUCP> robwah@auto-trol.UUCP (Robert Wahl) writes:
  8. >Writing "dprintf" is left as an exercise for the reader.  Using assembly
  9. >language, it may be an easy thing to prepend stderr to the variable argument
  10. >list and then call "fprintf".  Most likely, though, you will have to parse the
  11. >format string for the number and type of arguments in order to set up the
  12. >call to "fprintf".  If so, you might as well do it all in C (which at least
  13. >is portable), and do your output in stages.
  14. >
  15.  
  16. It is easy to write dprintf() using vfprintf() as follows:
  17.  
  18. #include <stdarg.h>
  19.  
  20. int dprintf(char *format, ...)
  21. {
  22.     va_list ap;
  23.  
  24.     va_start(ap, format);
  25.  
  26.     fprintf(stderr, "debug: ");
  27.     vfprintf(stderr, format, ap);
  28. }
  29.  
  30. --
  31. Derek Baum consulting at:
  32. Sun Microsystems    Internet: dbaum@East.Sun.COM
  33. (508)671-0456       UUCP: ...!sun!suneast!dbaum
  34.