Rob said:
So these two functions are different:
void foo(void);
and
void foo();
because the first one allows no arguments, but the second does. My
question is: In the implementation of the second function, how does
one get at those "optional" arguments?
I assume you mean something along these lines:
#include <stdlib.h>
#include <stdio.h>
void f();
int main(void)
{
f(1,2);
return 0;
}
void f(int i)
{
/* how can we get at both 1 and 2? */
}
The answer is, you can't reliably, portably, or legally. The Standard
(well, n869) says the following:
J.2 Undefined behavior
[#1] The behavior is undefined in the following
circumstances:
[big snip]
-- For a function call without a function prototype, the
number of arguments does not agree with the number of
parameters (6.5.2.2).
So there's no legal way to even call the function with "optional"
parameters, let alone access them.
Depending on your implementation, there might be a way (as long as
demons are flying out of your nose anyway) to get at that extra
argument, assuming that your program didn't crash or use your credit
card to buy nude koala bear photos from the web. But any method you did
find would likely be non-portable.
The upshot is that it just isn't useful. If you need variable
parameters, there are ways to do it. That isn't it.
Brian