I'm trying to write functions with optional arguments, e.g. a function that could be called 3 ways:
The problem is determining which arguments were supplied in a particular call, and which not.
The GNU C Library manual says,
"Some functions such as |open| take a fixed set of arguments, but occasionally ignore the last few. Strict adherence to ISO C requires these functions to be defined as variadic; in practice, however, the GNU C compiler and most other C compilers let you define such a function to take a fixed set of arguments--the most it can ever use--and then only /declare/ the function as variadic (or not declare its arguments at all!)."
This does indeed work, but I can't figure out how to determine how many arguments were actually supplied in a particular call. I would have thought the missing arguments would show up in the function as NULL pointers or something similar, but it doesn't seem to be so. Each argument, supplied or not, has an address. The unsupplied arguments seem to differ only in that their values are unpredictable.
I must be missing something obvious, but what?
Bucks vs Bytes Inc