[net.unix-wizards] 4.2 sprintf too painful?

rees@apollo.uucp (Jim Rees) (01/29/85)

I know this has been discussed before, but don't remember the answer.
What does this mean?  It's from the 4.2 stdio.h:

	#ifdef vax
	char	*sprintf();		/* too painful to do right */
	#endif

If I'm on a Gould or a Sun rather than a Vax, does sprintf return an
int, just like the sysV sprintf?  Doesn't seem very portable.
Does "too painful" refer to Vax assembly language programming?

Mail only, please.

rees@apollo.uucp (Jim Rees) (02/05/85)

I've gotten several answers to my question about this cryptic remark in
the Vax 4.2 /usr/include/stdio.h.  Lots of people asked me about it, so
I'll just post the answer once.
        - Jim Rees

#ifdef vax
char	*sprintf();		/* too painful to do right */
#endif

From: sun!shannon (Bill Shannon)
Date: mon, 4 feb 85 03:05:24
Subject: Re: 4.2 sprintf too painful?

Bill Joy put that in at Sun.  "Too painful" means too painful to hunt down
and fix all the unsupported programs at Berkeley that depend on Berkeley's
non-standard sprintf return value.  At Sun sprintf was recently changed to
be compatible with System V.  The lesson to be learned is, don't depend on
the return value of sprintf.

					Bill Shannon
					Sun Microsystems, Inc.

guy@rlgvax.UUCP (Guy Harris) (02/07/85)

> I've gotten several answers to my question about this cryptic remark in
> the Vax 4.2 /usr/include/stdio.h. ...
> 
> char	*sprintf();		/* too painful to do right */
> 
> Bill Joy put that in at Sun.  "Too painful" means too painful to hunt down
> and fix all the unsupported programs at Berkeley that depend on Berkeley's
> non-standard sprintf return value.  At Sun sprintf was recently changed to
> be compatible with System V.  The lesson to be learned is, don't depend on
> the return value of sprintf.

Another pointer along those lines:

Don't use %D, %O, %X, and the like.  Use %ld, %lo, %lx instead.
The System V (and System III) "printf" family uses %X to mean "hexadecimal
with capital A-F as digits" and doesn't support the others at all.  %ld, etc.
are supported on all "printf"s since V7.

And another tip; this one won't burn you on current systems, but CCI's
4.2BSD/System V Release 2 hybrid system (coming out this year on our Power 6
supermini and on some other systems) won't be happy if you do

	signal(SIGCHLD, SIG_IGN);

In vanilla 4.2BSD, this is equivalent to

	signal(SIGCHLD, SIG_DFL);

(well, 10 or so cycles more are spent in "psignal" dismissing the signal if
you do SIG_DFL instead of SIG_IGN, but then 99% of all processes SIG_DFL
it so who cares).  I decided that SIGCHLD (4.2BSD) and SIGCLD (System V)
were so close in functionality that they were combined into one signal.
The difference is that the S5 SIGCLD, when ignored, tells the system that
you are abandoning your current and future children.  If a child dies, no
zombie is left around.  As such, some programs ("rshd", if I remember correctly)
get confused when they do a SIG_IGN.

Hopefully, a list of all these sorts of warnings - including a "how to" on
dealing with the various TTY drivers - will end up in a document which 1) will
go out with our systems, 2) end up on USENET, and 3) maybe get published.

	Guy Harris
	{seismo,ihnp4,allegra}!rlgvax!guy

reno@bunker.UUCP (Jim Reno) (02/08/85)

> Another pointer along those lines:
> 
> Don't use %D, %O, %X, and the like.  Use %ld, %lo, %lx instead.

Another case to watch out for here: I got caught on a piece of code
that looked something like:
	printf("...%D%s..."...);
which intended, of course, to print out a value immediately followed
by a string. Unfortunately the source was being controlled by SCCS, which
turned the %D% into a date...

henry@utzoo.UUCP (Henry Spencer) (02/08/85)

> ...  "Too painful" means too painful to hunt down
> and fix all the unsupported programs at Berkeley that depend on Berkeley's
> non-standard sprintf return value.

Once again, Berkeley is getting credit/blame for something that was
(mostly) not their fault.  "char *" as the return type of sprintf was
in V7 (real V7, not x.yBSD mislabelled as V7), although it was undocumented.
This would seem to be a documentation botch, since "char *" was in both the
code and the lint-library.
-- 
				Henry Spencer @ U of Toronto Zoology
				{allegra,ihnp4,linus,decvax}!utzoo!henry