Trevor said:
The number of arguments passed to the following functions can be
determined - but how is this coded?
main (int argc, char *argv[])
main is a special function. You're not allowed to call it.
printf ( string format [, mixed args])
I would like to be able to write arbitrary functions that know how
many arguments were passed to them.
This is a function with a variable argument list. It's declared
something like:
int printf(const char* format, ...);
The ellipsis (...) indicates a variable list of arguments. The actual
number of arguments is determined from the format string. You have to
provide your own way for the function to find out the number and type
of arguments if you want to use variable argument lists. This is one
reason why you actually shouldn't do that. It's not type-safe and can
easiliy lead to errors that the compiler cannot detect. Another
disadvantage is that you can only pass POD types. Alternatively, you
can write a function or operator that 'writes' to an object and returns
a reference to that object, so that calls to that funciton/operator can
be stacked together. This is e.g. done in the C++ stream classes and
their operator<< and >>.