[英]how to call a function whose name is the same of the local variable name in c
How can i call a function whose name is same as that of the local variable in a calling function 如何在调用函数中调用名称与本地变量相同的函数
Scenario: 场景:
I need to call a function myfun(a,b) from some other function otherfun(int a,int myfun) . 我需要从其他函数otherfun(int a,int myfun)调用函数myfun(a,b)。 How can i do it? 我该怎么做?
int myfun(int a , int b)
{
//
//
return 0;
}
int otherfun(int a, int myfun)
{
// Here i need to call the function myfun as .. myfun(a,myfun)
// how can i do this?? Please help me out
}
int myfun(int a , int b)
{
return 0;
}
int myfun_helper(int a, int b)
{
return myfun(a,b);
}
int otherfun(int a, int myfun)
{
/* the optimizer will most likely inline this! */
return myfun_helper(a,myfun);
}
You can create a variable keeping a pointer to the myfun()
function. 您可以创建一个变量,该变量保留指向myfun()
函数的指针。 This will allow you to effectively 'alias' the original function without introducing an additional one. 这样,您就可以有效地“混淆”原始功能,而无需引入其他功能。
int myfun(int a, int b)
{
// ...
return 0;
}
static int (*myfunwrap)(int, int) = &myfun;
int otherfun(int a, int myfun)
{
myfunwrap(a, myfun);
}
Of course, you can replace myfunwrap
with any name you like. 当然,您可以使用任何喜欢的名称替换myfunwrap
。
The best idea would be to just chose a different name for your parameter. 最好的主意是为您的参数选择一个不同的名称。 The second best is this one, I think: 我认为第二好的是:
int otherfun(int a, int myfun)
{
int myfun_tmp = myfun;
// Here i need to call the function myfun as .. myfun(a,myfun)
{
extern int myfun(int, int);
myfun(a, myfun_tmp);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.