C is probably the only language you can do this in (except maybe Forth). Other languages either have no way of doing this, or don't treat data and code differently. (Feel free to add examples for other languages here.)
typedef int (*func_t)(char *);
int foo(char *x) {
printf("%s",x);
}
func_t p = foo; /* assign function pointer to p / return p("Narf!"); / call that function, and return the result */
And you need to do this why?
int atexit(void (*function)(void));
you can specify functions to be executed after main() finishes. You do this by calling atexit(functionname), as a function name
(int endwin() is an ncurses function).
atexit(endwin);
source.cpp:227: passing `int (*)()' as argument 1 of `atexit(void (*)())'
atexit(void)endwin);
source.cpp:227: void value not ignored as it ought to be
It is worth noticing that in languages where functions are first class objects (such as LISP and Scheme), passing around pointers to functions is entirely normal (and type safe); even in Java and Python Introspection allows type safe access to such functionality.
2 pages link to CastingPointerToFunction:
lib/main.php:944: Notice: PageInfo: Cannot find action page
lib/main.php:839: Notice: PageInfo: Unknown action