【发布时间】:2019-02-08 23:58:59
【问题描述】:
我有几个#define,定义了一个函数,我想将一些define传递给函数“ff”,所以它会调用它,下面是例子:
#define square(x) x*x
#define add(a,b) a+b
#define subtract(a,b,c) a-b-c
#include <stdio.h>
int ff(my_func)
{
//do something useful
my_func; //this should call square or add or subtract
//do something useful
}
int main()
{
printf("Square is %d \n",square(3)); //this works fine
printf("Add is %d \n", add(7, 8)); //this works fine
printf("Subtract is %d \n", subtract(21, 1, 8)); //this works fine
ff(square(10)); //this doesn't work, or it can be ff(add(5, 5));
return 0;
}
甚至有可能做到这一点吗?
【问题讨论】:
-
不完全 :( 在 C 语言中,您通常传递 function pointer。查看链接以获取解释和示例。如果您有任何具体问题,请回复。
标签: c function c-preprocessor