Path: utzoo!attcan!uunet!lll-winken!lll-lcc!ames!pasteur!ucbvax!decwrl!purdue!gatech!udel!princeton!phoenix!pupthy2!lgy From: lgy@pupthy2.PRINCETON.EDU (Larry Yaffe) Newsgroups: comp.unix.wizards Subject: #defines with variable # arguments Message-ID: <2855@phoenix.Princeton.EDU> Date: 11 May 88 19:01:09 GMT Sender: news@phoenix.Princeton.EDU Reply-To: lgy@pupthy2.PRINCETON.EDU (Larry Yaffe) Distribution: na Organization: Physics Dept, Princeton Univ Lines: 34 Are there any versions of cpp which allow one to define macros which accept variable numbers of arguments? I keep wishing for this every time I try to move code developed using sysV sprintf to a BSD system, so that I could do something like: #ifdef BSD_TO_5_SPRINTF char *(*Sprintf)() = sprintf ; #define sprintf(...) strlen (Sprintf (...)) #endif #ifdef 5_TO_BSD_SPRINTF int (*Sprintf)() = sprintf ; #define sprintf(str,...) ((void) Sprintf (str,...), str) #endif I know that some systems have `vsprintf' or some such thing which can be called from a sprintf replacement routine, but since the vprintf routines are not universally available (sadly), using them seems only to add to portability problems. Does anyone know why the folks at Berkeley chose to have their sprintf return its first argument, instead of the number of characters printed? I can't think of any good reason for this choice, since it throws away valuable information (the # of characters printed) which is painful to reacquire. On a separate topic: How common is the ability to initalize unions? (In C, of course.) Did this make it into the ANSI specs? ------------------------------------------------------------------------ Laurence G. Yaffe lgy@pupthy.princeton.edu Department of Physics lgy@pucc.bitnet Princeton University ...!princeton!pupthy!lgy PO Box 708, Princeton NJ 08544 609-452-4371 or -4400