[net.lang.c] USG and _doprnt

physics@utcs.UUCP (David Harrison) (12/10/84)

[chomperoo]
In non-USG versions, *printf calls _doprnt which does the work.
In our Hewlett-Packard 9000, there is no such function (usually
written in assembler so far as I know) and the man
claims that the printf familiy calls getc.  We have some code
here which was written including _doprnt, and wonder if there
is an equivalent call.  The HP runs essentially Sys III, and this
posting assumes that the disappearance of _doprnt is common
to Unix Support Group versions although I welcome correction. Even
more welcome is help in finding a substitute (including the varargs
stuff) for _doprnt.
		David Harrison
		Dept. of Physics
		Univ. of Toronto
		{allegra,ihnp4,linus,decvax}!utzoo!utcs!physics

guy@rlgvax.UUCP (Guy Harris) (12/12/84)

> In non-USG versions, *printf calls _doprnt which does the work.
> In our Hewlett-Packard 9000, there is no such function (usually
> written in assembler so far as I know) and the man
> claims that the printf familiy calls getc.  We have some code
> here which was written including _doprnt, and wonder if there
> is an equivalent call.  The HP runs essentially Sys III, and this
> posting assumes that the disappearance of _doprnt is common
> to Unix Support Group versions although I welcome correction. Even
> more welcome is help in finding a substitute (including the varargs
> stuff) for _doprnt.

Well, in System III "*printf" may call "_doprnt" in the VAX version, but
don't depend on it.  System III had undocumented routines called
"vprintf", "vsprintf", and "vfprintf" which did what you want - in effect,
they had calling sequences similar to "_doprnt" (we used "vsprintf" for
our "curses" implementation).  Those routines disappeared in System V,
and reappeared in System V Release 2 with documentation (along with "_doprnt",
which reappeared but without documentation).  Basically, all the "v*printf"
routines take a "va_list" argument (as seen on "varargs.h" :-)) instead of
their normal list of arguments to be printed; i.e., you call "vprintf" with

	vprintf(format_string, va_list_argument);

I *believe* that the argument would be a pointer to the first argument
in the list of things to be printed by the caller of "vprintf"; the same
pointer is passed to "_doprnt" as one of its arguments.

WARNING: as Henry Spencer and others have pointed out, there is *NO*
guarantee that any of the "varargs" stuff, including "v*printf", is
implementable on any particular machine and C implementation.  (Henry
knows whereof he speaks, because he worked on the Perq implementation
of C and UNIX - stack machines like the Perq tend to assume that the
*called* routine handles the argument list, which is very hard to do if
only the *calling* routine knows how many arguments it's passing).

There is no guarantee that they are available on any particular S3
implementation (they're not documented), and there is almost a guarantee
that they are not available under S5 Release 1 (they weren't provided).
There is no guarantee at all that "_doprnt" will be available, or will
work the way you expect it to, under *any* release of UNIX (except 4.2BSD,
where it is documented - a mistake, in my opinion; they should have written
their own "v*printf" implementation and used that, instead); Zilog's ZEUS V7
implementation didn't have it, because they had to screw around a lot
to get "printf" to work.  They put some arguments into registers in their
calling sequence, which means all the "varargs" stuff is a bitch.  I
have no idea if any ZEUS release has the "varargs" stuff.

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

john@physiol.OZ (John Mackin) (12/16/84)

In article <296@rlgvax.UUCP>, guy@rlgvax.UUCP (Guy Harris) writes:

> Zilog's ZEUS V7
> implementation didn't have [_doprnt], because they had to screw around a lot
> to get "printf" to work.  They put some arguments into registers in their
> calling sequence, which means all the "varargs" stuff is a bitch.  I
> have no idea if any ZEUS release has the "varargs" stuff.

This is all quite correct.  It's been about two years since I had to use
ZEUS, thankfully, but for as long as I was in contact with it there
was no working varargs.h by Zilog.  (They thoughtfully supplied a
PDP-11 one.)  After getting heartily sick of every second piece of
software I tried to port to the thing breaking where it tried to
do variadic routines, and being tired of re-inventing the wheel
each time, I did varargs.h for the ZEUS.  It works.  If anyone
is interested, I'll post it to net.sources (it's only short, and
is also a monument to human braindamage -- what I had to go through
must be seen to be believed).

John Mackin, Physiology Department, University of Sydney, Sydney, Australia
...!decvax!mulga!physiol.su.oz!john