home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / std / c / 2360 < prev    next >
Encoding:
Text File  |  1992-07-25  |  1.4 KB  |  50 lines

  1. Newsgroups: comp.std.c
  2. Path: sparky!uunet!decwrl!mips!tsoft!dennis
  3. From: bbs.dennis@tsoft.sf-bay.org (Dennis Yelle)
  4. Subject: can I call vprintf() twice in a row?
  5. Message-ID: <ZJ2FoB1w165w@tsoft.sf-bay.org>
  6. Sender: bbs@tsoft.sf-bay.org (BBS User)
  7. Organization: The TSoft BBS and Public Access Unix, +1 415 969 8238
  8. Date: Sat, 25 Jul 1992 01:19:58 GMT
  9. Lines: 39
  10.  
  11. #if 0
  12.     Is the following legal ansi c?
  13.     I beleave that it is, but if not, I would like to know why not.
  14.     Note in particular that vprintf() is called twice in a row.
  15.     I just discovered a vprintf() that changes arg_ptr when
  16.     I do this, causing the second vprintf to fail.
  17.     In case you are wondering, the bad vprintf() came from Watcom.
  18. #endif
  19.  
  20. /* --------- cut here for vfpf.c -------------------- */
  21.  
  22. #include <stdarg.h>
  23. #include <stdio.h>
  24.  
  25. void report( char *fmt, ...)
  26. {
  27.     va_list arg_ptr;
  28.     
  29.     va_start( arg_ptr, fmt);
  30.     vprintf( fmt, arg_ptr);
  31.     vprintf( fmt, arg_ptr);  /* Yes, we want to print it twice.     */
  32.                              /* In the original program, the second */
  33.                              /* was vfprintf to a log file.         */
  34.     va_end( arg_ptr);
  35. }
  36.  
  37. main( int argc, char **argv)
  38. {
  39.     int a;
  40.     
  41.     for( a=0; a<argc; a++) {
  42.         report( "arg %d is %s\n", a, argv[a]);
  43.     }
  44.     return 0;
  45. }
  46. /* --------- cut here for vfpf.c -------------------- */
  47.  
  48. --
  49. Dennis Yelle (bbs.dennis@tsoft.sf-bay.org)
  50.