home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!cs.utexas.edu!qt.cs.utexas.edu!yale.edu!ira.uka.de!gate.fzi.de!dockhorn
- From: dockhorn@fzi.de (Patrick Dockhorn)
- Subject: Summary: Macro with variable number of arguments
- Message-ID: <1992Jul25.140204.17746@fzi.de>
- Followup-To: poster
- Keywords: macro arguments variable number summary
- Sender: news@fzi.de (FZI-news)
- Reply-To: dockhorn@fzi.de
- Organization: Forschungszentrum Informatik (FZI), Karlsruhe, Germany
- Date: Sat, 25 Jul 1992 14:02:04 GMT
- Lines: 68
-
- Two weeks ago I posted a request to solve the problem
- of having a macro with a variable number of arguments.
- In fact, the question was a little bit more detailed:
- I wanted a macro that allowed me to pass parameters to it
- in the way you call the printf - function.
- I knew of the solution with the double parenthesis, i.e.
-
- #define DEBUG_OUT (x) printf x
-
- and calling the macro with e.g.
-
- DEBUG_OUT(("File %s, Line %d : Fatal error !",__FILE__,__LINE__));
-
-
- My special problem was how to use this trick to write the error text to
- stderr instead of stdout. The straight-forward solution to this was given
- to me by Leo (leo@ine.philips.nl) and Jos (jos@and.nl):
-
- #define DEBUG_OUT(x) fprintf x
-
- and then use it (again) with the argument list enclosed in double parentheses:
-
- DEBUG_OUT((stderr,
- "file %s, line %d - error %d occured.",
- __FILE__,__LINE__,error_code));
-
-
- The other solutions all mentioned the use of a variable arg list function;
- they all looked more or less like this:
-
- #define DEBUG_OUT(x) eprintf x
-
- #include <stdarg.h> /* vararg.h on some systems */
- #include <stdio.h>
-
- /* just like printf, but to stderr */
- int eprintf(const char *format, ...)
- {
- va_list args;
- int retval;
-
- va_start(args, format);
- retval = vfprintf(stderr, format, args);
- va_end(args);
- return retval;
- }
-
-
- I'd like to thank the following net.people for their
- suggestions; they have been very helpful:
-
- Fergus Henderson (fjh@munta.cs.mu.OZ.AU),
- Gene Ressler (ressler@cs.cornell.edu),
- Michael Gordon (mfg@castle.edinburgh.ac.uk),
- Patrick Schaaf (bof@midget.saar.de)
- Raymond Chen (raymondc@microsoft.com)
- Jutta Degener (jutta@cs.tu-berlin.de)
-
-
- Patsch
-
- --
- Patrick Dockhorn Forschungszentrum Informatik, Karlsruhe/Germany.
- INTERNET: dockhorn@fzi.de There are two rules for success in life:
- BITNET : ukew@dkauni2.bitnet Rule 1: Don't tell people everything you know.
-
-
-
-