🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.arch
Article #13330

sprintf return value (was: String Processing Instruction)

#13330
From: msb
Date: Mon, 30 Mar 1987 19:30
22 lines
1663 bytes
> > 	sprintf(p, "format%d%s", args...); p+= strlen(p);

> Wouldn't it have been nice if strcpy(), strcat(), sprintf(), etc.
> had been designed to return a pointer to the END of the string,
> (or a count of the number of characters in the string)?

In some C implementations, sprintf() DOES return a count of the number
of characters that it wrote.  I find this behavior in a System V manual,
for instance, and on VMS.

Since both behaviors existed, the ANSI people were able to choose the more
useful one, and the October 1986 draft mandates that sprintf() returns
a count.  Unfortunately this does not apply to the other string functions.

Also unfortunately, the new book "Portable C and UNIX System Programming"
by "J. E. Lapin" misses this one.  (That's why I had to check manuals...)

Meanwhile, until ANSI C is universal, we should all be careful NOT to assume
that we know what type sprintf() returns...

Mark Brader	      "Perhaps their software was written by a Byzan-tine-ager"
utzoo!sq!msb						      -- Peter Neumann
Technical Details
Message-ID: <1987Mar30.143052.16783@sq.uucp>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!utfyzx!sq!msb
References: <6448@watmath.UUCP>

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!utgpu!utfyzx!sq!msb
From: msb@sq.UUCP
Newsgroups: comp.arch,comp.lang.c
Subject: sprintf return value (was: String Processing Instruction)
Message-ID: <1987Mar30.143052.16783@sq.uucp>
Date: Mon, 30-Mar-87 14:30:52 EST
Article-I.D.: sq.1987Mar30.143052.16783
Posted: Mon Mar 30 14:30:52 1987
Date-Received: Tue, 31-Mar-87 05:33:03 EST
References: <6448@watmath.UUCP>
Reply-To: msb@sq.UUCP (Mark Brader)
Distribution: na
Organization: SoftQuad Inc., Toronto
Lines: 22
Checksum: 42252
Summary: nonportable, but ANSI did it right