varargs question

Jamie Mazer mazer at bek-owl.caltech.edu
Sun Jul 16 09:38:55 AEST 1989


Recently, I have found I needed something like the C++ form
function (I believe this came up pretty recently in another
list as well). Our masscomp libs don't have vsprintf() etc, so
as a kludge, I first tried to cobble something together along
the lines of:
	format(a1, a2, a3, ... , a10)    /* ugly, but it often works ;-) */
	  char *a1, *a2, *a3, ... , *a10)
	{ ... sprintf(buf, a1, a2, a3, ... , a10); return(buf) ... }

However, then someone suggested I try the following solution:
	format(va_alist)
	  va_dcl
	{ ... sprintf(buf, va_alist); return(buf); ... }

The question is, is the second method a valid one? It seems to
work on our SUNs, but not reliably on the Masscomp, though for
the life of me, I can't figure out where and when it blows up.

Is it legit to pass va_alist into another function like that?
If so, then why are the vprintf() functions necessary at all?

Thanks,
/Jamie
  UUCP: {rutgers,ames}!cit-vax!bek-owl!mazer
  ARPA: mazer at bek-owl.caltech.edu  "It's a fine line between line between
BITNET: jmazer at caltech.bitnet       clever and stupid" -- Spinal Tap



More information about the Comp.unix.wizards mailing list