- //by baihacker
- #include <stdio.h>
- #define MAKE_OPERATOR(result, ptype, name) result * name(result* (*action)(result *, ptype), result * it, ptype p, int n){return n--?(name(action, it, p, n),action(it, p)):it;}
- MAKE_OPERATOR(int, int, foo)
- int* add(int* it, int n)
- {
- *it += n;
- return it;
- }
- int main(int argc, char* argv[])
- {
- int n = 0;
- foo(add, &n, 1, 10);
- printf("%d/n", n);
- return 0;
- }
化循环为递归的算子
最新推荐文章于 2020-11-23 20:22:40 发布