Partially Applied Functions in C — Leandro Pereira

<![endif] [if lt IE 7]> <p class="chromeframe">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> or <a href="http://www.google.com/chromeframe/?redirect=true">activate Google Chrome Frame</a> to improve your experience.</p> <![endif] Leandro Pereira Home About 20 July 2013 There are some functions in the standard C library that takes a function pointer to be used as a callback later on. Examples include atexit() and signal() . However, these functions can’t receive an arbitrary pointer (which could hold some important program state) in addition to the function pointer, so you’re left with pesky global variables: /* You have: */ atexit ( foo ); /* foo() will have to fetch program state from globals */ /* Instead of: */ static struct program_state state ; atexit ( foo , ...

Linked on 2014-09-19 19:14:44 | Similar Links