I can build this example with no errors with gcc -std=C99 -Wall
:
void dummy() {}
int main(void) {
dummy(1, 2, 3);
dummy(120, 144);
}
The disassembly shows that the function is indeed called twice:
main:
.LFB1:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
movl $15, %edx
movl $14, %esi
movl $12, %edi
movl $0, %eax
call foo
movl $300, %esi
movl $200, %edi
movl $0, %eax
call foo
movl $0, %eax
popq %rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc
I admit that this code should not exist, but, it is allowed and I am wondering in which special case it would be useful.
Any clues?
EDIT
The question calling-c-functions-with-too-many-arguments does not answer this question. It gives information about how to use varadic but it does not provide an example in which an incomplete declaration can be useful.
The question func-vs-funcvoid-in-c99 also does not answer the question. It explains the difference between incomplete and complete prototype which is not my question.
So, it seems my question is not clear enough and I am going to give another example:
Let's imagine I would really leverage an incomplete declaration to use variable arguments without using the varadic method so I wrote my example as:
int main(void) {
dummy(1, 2, 3);
dummy(1, 2, 3, 4, 5, 6, 7, 8);
}
Accoding to the calling conventions, the first function will use the CPU registers to pass the parameters while the second call will use the stack.
Now in my dummy
function, how can I read these arguements and know whether or not the stack was used?