This question is an offshoot of `f(void)` meaning no parameters in C++11 or C?
Several have answered that question and opined that in C, the meaning of the function prototype
void func ()
is that func is a function returning nothing (void) and whose parameters are unknown at this time.
Further they have opined that one could make this declaration and then invoke the function with some arguments such as:
func (1, 2, 3);
So, I did this, I made a test to verify that this works and I'm not surprised that it does.
Here is func.c, which contains main()
#include <stdio.h>
extern void func ();
int main (int ac, char ** av)
{
func (1, 2, 3);
return 0;
}
And here is func1.c which contains the function func()
#include <stdio.h>
void func (int a, int b, int c)
{
printf ( "%d, %d, %d\n", a, b, c );
}
And here are my question(s)
Question 1:
When I run this program, I get, as expected the output 1, 2, 3.
Is this a safe way to write code; i.e. can one assume that the ABI will reliably ensure that the invocation of func()
in main()
will put the three parameters in the right places (registers, stack, whatever) for func()
to find them?
Question 2:
If the answer to 1 above is that it is a safe thing to do, then does your answer change if func()
is implemented in some language other than C?