This situation can only occur without name mangling (I believe), so the below code is C. Say there is a function A defined in A.c as
void A(int x, int y){
//Do stuff
}
Now there is also a separate file B.c:
extern "C"{
void A(int x, int y, int z);
}
void B(){
A(1, 2, 3);
}
A is initially declared to have only 2 arguments yet when declared in B.c it has an extra one, and it is called with that third in B(). I know it is possible to make this situation occur, for example when linking with fortran subroutines, OR when dynamically linking.
I imagine it is unsafe to pass an extra argument to a function, can anyone explain what is happening in memory when a function is called and arguments are passed to it? And, therefore, how safe it is to pass this "extra" argument that is neither used nor wanted.
Is it possible that the extra argument overwrites a space in memory that is used within the function? Or does the function call to A allocate space in memory for the arguments then tell A where the beginning of the argument memory block is, A reads out the first two arguments and ignores the last, making it completely safe?
Any information on the function would be greatly enlightening, thanks.