Path: utzoo!mnetor!uunet!husc6!bbn!rochester!srs!dan From: dan@srs.UUCP (Dan Kegel) Newsgroups: comp.lang.c Subject: Varargs for Macros? Message-ID: <600@srs.UUCP> Date: 19 Feb 88 20:37:46 GMT Distribution: na Organization: S.R.Systems Lines: 24 We now have a nice standard way of writing functions that take variable numbers of arguments. Is there any corresponding capability for macros? For example, I'd like to have a macro that calls write() and prints a fancy error message upon failure. It would expand this WRITE(fd, buf, bytes, "Error at record %d of %s", recNum, fileName); to this: if (write(fd, buf, bytes) != bytes) fprintf(stderr, "Error at record %d of %s", recNum, fileName), exit(1); regardless of the number of arguments to fprintf. This example is a little poor, I admit, but it demonstrates passing a variable number of parameters to a macro. I suppose the macro definition might use elipses: #define WRITE(i, p, n, s, ...) \ if (write(i, p, n) != n) \ fprintf(stderr, s, ...), \ exit(1) Anybody else ever want to do this sort of thing? -- Dan Kegel srs!dan@cs.rochester.edu dan%srs.uucp@cs.rochester.edu rochester!srs!dan