How to pass a macro as an argument in a C function?

c, function-pointers, macros

Solution

You can't do that.

Use normal functions instead:

int sum(int x, int y)
{
    return x+y;
}

//...

just_another_function(10, sum);

Note: `just_another_function` must accept `int (*)(int, int)` as the second argument.

typedef int (*TwoArgsFunction)(int, int);
int just_another_function(int x, TwoArgsFunction fun);

Problem

I want to pass a macro as an argument in a C function, and I don't know if it possible. I would like to see this operation, for instance: I have these macros: ``` #define PRODUCT(A, B) ((A) * (B)) #define SUM(A, B) ((A) + (B)) ``` And then I have this function with the following signature: ``` int just_a_function(int x, MACRO_AS_PARAMATER_HERE); ``` and then i want to call this function like: ``` just_a_function(10, SUM); ``` is it possible? Thanks

Original source