From C to C++
- slide 18 : 29
Function types
Functions in C can be used as data of function type
Only two possible operations on a function
Calling the function
Take the address of the function
Functions as types and data
Dealt with by means of function pointers
Use of the
dereference operator
and the
address operator
is often implicit
Functions are first class data in C, but they are not closures
The declaration syntax is obscure - difficult to read
C program with function pointer.
Same program - without explicit use of the address and dereferencing operators.
Same program - using a typedef to capture the function type.
An array of functions