Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!philabs!cmcl2!seismo!hao!hplabs!sri-unix!FIRTH%TARTAN@CMU-CS-C.ARPA From: FIRTH%TARTAN@CMU-CS-C.ARPA Newsgroups: net.unix-wizards Subject: Function with variable number of args Message-ID: <1273@sri-arpa.UUCP> Date: Mon, 25-Jun-84 14:39:37 EDT Article-I.D.: sri-arpa.1273 Posted: Mon Jun 25 14:39:37 1984 Date-Received: Sat, 30-Jun-84 01:29:58 EDT Lines: 23 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. -------