The source code example is:
int add2(int a0, int a1)
{
return a0+a1;
}
int add4(int a0, int a1, int a2, int a3)
{
return a0+a1+a2+a3;
}
int (*fptr)(int a0,int a1,int a2,int a3,int a4,int a5,int a6,int a7);
int main()
{
volatile int ret0;
int a0=0;
int a1=1;
int a2=2;
int a3=3;
int a4=4;
int a5=5;
int a6=6;
int a7=7;
fptr = add4;
ret0=fptr(a0,a1,a2,a3,a4,a5,a6,a7);
return ret0;
}
In this example we have function pointer with 8 arguments. I'am assigning to this pointer the pointer of the function which contains 4 arguments. In this case, compiler may generate assembly code, which will use stack and registers, which are not used in the target function (with 4 arguments). Is it legal to assign and use address of function which has less arguments than the function pointer? Is it safe to use such a programming pattern?