1

I am a math student, recently I am thinking if

$f:A\to B$ and $g:B\to C$ are two functions (pointers) written in C, where $A,B,C$ are just three data types, is there a mechanism in C that allows creating a function pointer $h$ that when applies to some $x\in A$ has the same effect as $f\circ g$? i.e., $h(x)=g(f(x))$?

I know for two given function $f,g$, I can write a new function that returns $g(f(x))$, but I am asking if we can compose any two function pointers without writing a new function. This is useful when I pass a function pointer to some functions like qsort.

Kaa1el
  • 337
  • 3
  • 10
  • 6
    You're talking about higher-order functions; in C functions are not first-class and thus doing this wouldn't be straight forward. Have a look at [this](http://stackoverflow.com/questions/2535631/higher-order-functions-in-c); it seems to be a duplicate. – legends2k Feb 19 '14 at 03:32

0 Answers0