home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!munnari.oz.au!cs.mu.OZ.AU!markkj
- From: markkj@mullian.ee.mu.OZ.AU (Mark Johnston)
- Subject: Variable arguments & macros...
- Message-ID: <markkj.711771545@munagin>
- Summary: How???
- Keywords: macros, varargs
- Sender: news@cs.mu.OZ.AU
- Organisation: Computer Science Department, Melbourne University, Australia
- Organization: Computer Science, University of Melbourne, Australia
- Date: Wed, 22 Jul 1992 02:19:05 GMT
- Lines: 43
-
-
- I'm wondering if anyone has any really devious ways of writing macros
- so that variable arguments can be used. The problem is that I have a function
- that does error handling for a program, and it takes variable arguments:
-
- int writeErrorMsg(int quit, char *file, int line, char *format, ...)
- {
- /* ... */
- }
-
-
- The macros are:
-
- #define error(x) writeErrorMsg(0, __FILE__, __LINE__, x)
- #define fatal(x) writeErrorMsg(1, __FILE__, __LINE__, x)
-
-
- Last but not least, I'm using the functions in the following way:
-
- error("The error code is %1d.", errCode);
-
-
- I'm using the macros so that the code is more readable, without the
- preprocessor thingys there to obstruct the view. The compiler is gcc,
- on a sun-4/75 (ie no problems with badly written compilers...)
-
-
-
- Any brilliant ideas?
-
- Thanks in advance...
-
- Mark Johnston.
-
-
- ================================================================================
- | markkj@marvin.its.unimelb.edu.au
- Real programmers get it right the first time: | markkj@munagin.ee.mu.oz.au
- | markkj@krang.vis.citri.edu.au
- #include "/dev/tty" | markkj@mundil.cs.mu.oz.au
- | mkj@tauon.ph.unimelb.edu.au
- ================================================================================
-
-