Function with variable number of args
FIRTH%TARTAN at CMU-CS-C.ARPA
FIRTH%TARTAN at CMU-CS-C.ARPA
Tue Jun 26 04:39:37 AEST 1984
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.
-------
More information about the Comp.unix.wizards
mailing list