Function pointer to different functions with different arguments in C

前端 未结 6 1061
独厮守ぢ
独厮守ぢ 2020-12-31 08:48

I have two functions with variable number and types of arguments

double my_func_one(double x, double a, double b, double c) { return x + a + b + c }
double my         


        
6条回答
  •  Happy的楠姐
    2020-12-31 09:04

    My question is, for this scenario, Can I at all define a function pointer?

    No. (Other than by dirty typecasting.)

    Is there any other way to do this?

    Your best bet is to create a wrapper function for one of your existing functions. For example:

    double my_func_one_wrapper(double x, double p[], double c) {
        return my_func_one(x, p[0], p[1], c);
    }
    

    That way, you have two functions with the same signature, and therefore the same function-pointer type.

提交回复
热议问题