sprintf(3s) query

Richard A. O'Keefe ok at quintus.uucp
Fri Dec 16 11:05:22 AEST 1988


In article <9181 at smoke.BRL.MIL> gwyn at brl.arpa (Doug Gwyn (VLD/VMB) <gwyn>) writes:

>#ifdef vax
>char	*sprintf();		/* too painful to do right */
>#endif
>
>Note that Sun MUST have changed this in order for it to apply to
>their (definitely non-VAX) machines.

In point of fact, at least as of SunOS 3.2, they DIDN'T.
So much for "MUST".  The effect is that in SunOS, if you wanted the
buffer pointer, you had to explicitly declare sprintf() yourself.

>I hope by now all the BSD code that depends on the value of
>sprintf() being anything in particular has been changed to use
>some other method.  Usually, something like
>	buf[0] = '\0';
>	(void)sprintf(buf, fmt, args);
>	if (buf[0] == '\0')
>		/* error */
>is sufficient (it works with both definitions of sprintf()).

Except that it doesn't work with either.  Consider
	sprintf("%.*s", len, ptr);
when len happens to be 0.  By the way, what _are_ the output error
conditions that *printf() can detect other than by crashing?



More information about the Comp.lang.c mailing list