gripe: variable arg lists

Chris Torek chris at umcp-cs.UUCP
Tue Nov 20 09:54:02 AEST 1984


> > As to why _doprnt() was used: that's pretty easy.  There is no standard
> > analog to printf which accepts a variable argument list *as an argument*.

> There is, however, a portable mechanism to do this job:  sprintf followed
> by passing the resulting string to whoever wants it.

But this only works for (a large number of) specific cases.  Suppose a
string could be arbitrarily long?  Then you need an arbitrarily long
buffer.  A function-based printf would seem to be the ``best'' way to
be everything to everyone, but there is no such beast. Sigh.

Granted, one should use sprintf when possible.  But (as many have found
out) sprintf is dangerous, since it will merrily overflow buffers and
scribble on top of useful data.  snprintf() and sxprintf() help, but
only those who have implemented Patrick Powell's changes have those.
Again, sigh.
-- 
(This line accidently left nonblank.)

In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (301) 454-7690
UUCP:	{seismo,allegra,brl-bmd}!umcp-cs!chris
CSNet:	chris at umcp-cs		ARPA:	chris at maryland



More information about the Comp.lang.c mailing list