Question: Big picture: I have a module with functions and a module with procedures and functions over those functions.

When I combine two functions (from function's module interface):

```
double f1(double alpha, double x);
double f2(double beta, double x);

```

In several ways, (one of them is adding):

```
double OP_Addition(double (*f)(double,double) , double (*g)(double,double), double param1, double param2, double x);

```

Gives no problem with the following (piece of) implementation:

```
z1 = (*f)(param1, x);
z2 = (*g)(param2, x);
y = z1 + z2;
return y;

```

But when I want to return a pointer to a "new" function, something like:

```
void *OP_PAdd( double (*f)(double,double), double param3 );

```

I can not get it to work properly, neither make the right "call". I want to have use the output "function" as input in other functions.

Answer: 
When returning a function from another function, the cleanest way to do this is with a `typedef`:

```
typedef double (*ftype)(double, double);

```

Then you can declare your function like this:

```
ftype OP_PAdd( ftype f, double param3 )
{
    ....
    return f1;
}

```

You can do this without a `typedef`, but it's messy:

```
double (*OP_PAdd( double (*f)(double,double), double param3 ))(double,double)
{
    return f1;
}

```

So when you have function pointers as either parameters or return values of other functions, use a `typedef`.

EDIT:

While you could declare the type like this:

```
typedef double ftype(double, double);

```

You can never directly use a type like this in practice. A function can't return a function (only a pointer to a function), and a variable of this type can't be assigned to. 

Also, you don't need to explicitly dereference a function pointer to call the function, so the fact that the pointer itself is hidden is not a big issue. It's also convention to define function pointers as a `typedef`. From the [man page for `signal`](http://linux.die.net/man/2/signal):

```
   #include <signal.h>

   typedef void (*sighandler_t)(int);

   sighandler_t signal(int signum, sighandler_t handler);

```
in C, you can return pointer to function, but to do that, function needs to exist first, and dynamically creating functions is not something C says is possible, never mind how to do it

if your code is going to work only on one OS and one processor (and probably some other restrictions), you may be able to:

1. allocate page of memory
2. write data and machine code doing what you want, calling functions passed by pointer etc.
3. change memory protection from read/write to read/execute
4. return pointer to created function
5. don't worry that you you need 4kB per function

there probably are somewhere libraries for that, but necessarily not portable