c*******h 发帖数: 1096 | 1 刚google了一下,可以这样搞
#include
int f(int x, int y) {
return x+y;
}
int g(int (*Afun)(int x), int x) {
return Afun(x);
}
int main(void) {
int y = 100;
int (*Afun)(int);
Afun = ({ int $(int x){ return f(x,y); } $; });
int x = 20;
int z = g(Afun, x);
printf("z = %d\n", z);
}
gcc是work的,不过我换到intel的compiler就不work了 |
|
c*******h 发帖数: 1096 | 2 就是部分的arguments可以动态定死,剩下的才是真正的argument。就像
y = 100;
Afun = @(x)f(x,y);
g(Afun);
在C里面怎样定义Afun? |
|
t****t 发帖数: 6806 | 3 there's no built-in support for this in C. You can achieve the similar
result with c++ std::bind, e.g.
auto afun = std::bind(f, std::placeholders::_1, y);
afun(x); |
|
s*******3 发帖数: 52 | 4 我这里5吨的全部换掉,80% afun furnace, 价格5500。给你参考。 |
|