Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!henry From: henry@utzoo.UUCP (Henry Spencer) Newsgroups: net.unix-wizards Subject: Re: Function with variable number of args Message-ID: <4011@utzoo.UUCP> Date: Sat, 30-Jun-84 01:47:37 EDT Article-I.D.: utzoo.4011 Posted: Sat Jun 30 01:47:37 1984 Date-Received: Sat, 30-Jun-84 01:47:37 EDT References: <1273@sri-arpa.UUCP> Organization: U of Toronto Zoology Lines: 39 >I was amazed to read this statement in a recent post: > > There is *no* fully machine-independent way to write a > function which takes a variable number of arguments, even > if all the function is trying to do is to pass its argument > list on to another function. > >The language BCPL has precisely this feature, and as far as I know >there has been no major problem with it in 20 years. The way to >write the function is to declare it with the maximum number of >arguments, and you can scan the argument list sequentially by >simply building a pointer to the first argument and stepping it: > > ptr := LV arg1 > ... > ptr := ptr + (LV arg2 - LV arg1) > >(LV in BCPL is & in C). The language semantics requires the args to be >stored in consecutive cells, though they may run upwards or downwards in >memory, hence the above code. I've never heard of any implementation >difficulties, and have never encountered any myself in the BCPL ports >I've done. For one thing, C is not BCPL, and C does *not* require consecutive cell allocation of arguments. So you can't (in principle) depend on that. There are C compilers that put some of the arguments in registers, for example. (Please don't tell me that these compilers run into trouble with various things; I'm quite aware of this. But they do exist.) For another thing, while I respect your BCPL porting experience, I would say that you've never tried to implement BCPL on really difficult machines. There exist machines -- with Unix implementations running on them -- which absolutely require that the size of the argument list of a given function be a compile-time constant, as a fundamental assumption of their only call primitive. Such machines break *all* the simplistic variable-arguments techniques; really heavy kludging is required to make things work. -- Henry Spencer @ U of Toronto Zoology {allegra,ihnp4,linus,decvax}!utzoo!henry