home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / c / 11418 < prev    next >
Encoding:
Text File  |  1992-07-21  |  1.8 KB  |  57 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!munnari.oz.au!cs.mu.OZ.AU!markkj
  3. From: markkj@mullian.ee.mu.OZ.AU (Mark Johnston)
  4. Subject: Variable arguments & macros...
  5. Message-ID: <markkj.711771545@munagin>
  6. Summary: How???
  7. Keywords: macros, varargs
  8. Sender: news@cs.mu.OZ.AU
  9. Organisation: Computer Science Department, Melbourne University, Australia
  10. Organization: Computer Science, University of Melbourne, Australia
  11. Date: Wed, 22 Jul 1992 02:19:05 GMT
  12. Lines: 43
  13.  
  14.  
  15.     I'm wondering if anyone has any really devious ways of writing macros
  16. so that variable arguments can be used.  The problem is that I have a function
  17. that does error handling for a program, and it takes variable arguments:
  18.  
  19. int writeErrorMsg(int quit, char *file, int line, char *format, ...)
  20. {
  21.  /* ... */
  22. }
  23.  
  24.  
  25.     The macros are:
  26.  
  27. #define error(x) writeErrorMsg(0, __FILE__, __LINE__, x)
  28. #define fatal(x) writeErrorMsg(1, __FILE__, __LINE__, x)
  29.  
  30.  
  31.     Last but not least, I'm using the functions in the following way:
  32.  
  33.     error("The error code is %1d.", errCode);
  34.  
  35.  
  36.     I'm using the macros so that the code is more readable, without the
  37. preprocessor thingys there to obstruct the view.  The compiler is gcc, 
  38. on a sun-4/75 (ie no problems with badly written compilers...)
  39.  
  40.  
  41.     
  42.     Any brilliant ideas?
  43.  
  44.     Thanks in advance...
  45.  
  46.         Mark Johnston.
  47.  
  48.  
  49. ================================================================================
  50.                                               | markkj@marvin.its.unimelb.edu.au
  51. Real programmers get it right the first time: | markkj@munagin.ee.mu.oz.au
  52.                                               | markkj@krang.vis.citri.edu.au
  53.     #include "/dev/tty"                       | markkj@mundil.cs.mu.oz.au
  54.                                               |    mkj@tauon.ph.unimelb.edu.au
  55. ================================================================================
  56.  
  57.