[net.unix-wizards] variable number of arguments

sah@mips.UUCP (Steve Hanson) (08/06/85)

One practice in C that is both deeply ingrained in UNIX (e.g. printf, doprnt.c)
and non-obvious to the reader are functions that take a variable number.
The method is to take the address of one of the formal parameters and
reference indirectly the others (which aren't explicit in the 
formal parameter declaration list). To help standardize the usage of this
practice the varargs.h macros were developed and now the proposed ANSI draft
includes the stdarg.h macros.  

My questions are:
  (1) Are these macros being used by developers ?
  (2) What is the reaction to them ?
  (3) Is old code modified to use them?
  (4) What is the effect when an optimizing compiler passes arguments 
      in registers? 
  (5) Do any implementations require the macros be used?

smithrd@rtp47.UUCP (Randy D. Smith) (08/08/85)

In article <159@mips.UUCP> sah@mips.UUCP (Steve Hanson) writes:
>One practice in C that is both deeply ingrained in UNIX (e.g. printf, doprnt.c)
>and non-obvious to the reader are functions that take a variable number.
[of arguments]
>
>My questions are:
>  (1) Are these macros being used by developers ?
Yep.
>  (2) What is the reaction to them ?
It works.  The other way doesn't on many implementations.
>  (3) Is old code modified to use them?
Yes.  In particular, I've modified dbx (the 4.2 BSD debugger)
to use varargs with complete success.  I also modified ctrace
(a Sys. V Rel. 2 debugging utility) to use varargs instead of
passing a single argument of whatever type on the calling side,
and expecting a "union { all possible types }" on the called side.
GAK!

I encourage more people to check out the man page for the varargs
package, and to actually use it.  IN PARTICULAR, if you have ever
tried running some arbitrary piece of code on a UNIX (tm of AT&T
Bell Labs) or UNIX-lookalike, had the code to break, then determined
that the UNIX you are using "grows the stack in the ``wrong'' direction",
then consider complaining to the bozo that wrote the non-portable
code rather than considering the UNIX to be brain damaged.

-- 
				Randy D. Smith	(919) 248-6136
			   Data General, Research Triangle Park, NC
			 <the known world>!mcnc!rti-sel!rtp47!smithrd

ark@alice.UUCP (Andrew Koenig) (08/12/85)

I am the original author of the varargs package.  If you encounter
interesting issues while using it, I would appreciate hearing about them.


		Andrew Koenig
		research!ark		<--- preferred address