var args - (nf)

John Bruner jdb at mordor.UUCP
Fri Nov 11 02:14:37 AEST 1983


Now that all of the mail has come in, here is a summary of the
responses I received to my inquiry about argument passing in C.

The consensus was that it is "legal" to implement a compiler for
which functions that do not use "varargs" must be called with the
same number of arguments with which they were defined.  This would
mean that if the 4.2BSD "open" were declared as

	open(path, flags, mode)
	char *path;
	int flags, mode;
	{

then calling it in the old way

	open("/dev/null", 0);

would be incorrect.  Although such an implementation is "legal" it
is undesirable because many programs from more permissive
environments (e.g. the VAX) depend upon this characteristic.  (One
example of this occurs in the Portable C compiler itself.)

Several people also pointed out that right-to-left evaluation of
the arguments would place the first argument at a constant offset
from the called routine's stack frame, regardless of the direction
of stack growth.  I should have mentioned in my original inquiry
that we chose left-to-right evaluation because we wanted the
arguments to be stored with ascending addresses.  Some C programs
desire this characteristic as well.

The other method for handling cases such as the one above is to use
a register as an argument pointer.  The AP points to the first
argument and all variables are referenced with positive offsets from
the AP.

We are changing the calling sequence for the S-1 compiler from one
calling mechanism (JSR/RETSR) to another one (CALL/UNCALL) that
was originally intended for another language implementation.  This
will allow us to pass an argument pointer in an efficient way.
All of the usual "tricks" with regard to argument passing in C
should then work "correctly".

Thanks for all of the help.

	John Bruner
	S-1 Project/Lawrence Livermore National Laboratory



More information about the Comp.lang.c mailing list