Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site mordor.UUCP Path: utzoo!linus!decvax!decwrl!mordor!jdb From: jdb@mordor.UUCP (John Bruner) Newsgroups: net.lang.c Subject: Re: var args - (nf) Message-ID: <136@mordor.UUCP> Date: Thu, 10-Nov-83 11:14:37 EST Article-I.D.: mordor.136 Posted: Thu Nov 10 11:14:37 1983 Date-Received: Tue, 15-Nov-83 19:16:08 EST References: <2346@hp-pcd.UUCP> Organization: S-1 Project, LLNL Lines: 46 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