sprintf(3s) query

Chris Torek chris at mimsy.UUCP
Thu Dec 8 22:17:03 AEST 1988


In article <1102 at entropy.ms.washington.edu> charlie at mica.stat.washington.edu
(Charlie Geyer) writes:
>But [4.xBSD, x < 3tahoe] /usr/include/stdio.h has the following
>interesting item
>
>  #ifdef vax
>  char    *sprintf();             /* too painful to do right */
>  #endif
>
>so it doesn't define what sprintf returns (and by default C assumes
>that sprintf returns an int).

>  (1) What is "too painful to do right" and why?

sprintf() is supposed to return an int, namely the count of characters
printed.  There were numerous programs that depended on it returning
a `char *'.  These have been fixed; it was only mildly painful.

>  (2) Why doesn't lint give an error for [a call to fprintf] as well?

Your lint library (for Suns and IBM ACIS) does not incorrectly declare
fprintf() as returning `char *'.  Whether your sprintf() actually
returns `char *' (as not-quite-defined in stdio.h) is another question
entirely.  Poking around in the SunOS 3.2 sources, I find both versions.
Which one gets used I have no idea.

This is fixed in 4.3BSD-tahoe, where sprintf() returns int---no options.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.lang.c mailing list