What are function pointers and what are their typical use cases in systems-level C++?
Last updated
A function pointer (declared
ret(*name)(args)) stores a function's address so behavior can be called or passed at runtime. It carries no state.Typical systems uses: callbacks to C APIs (
qsort,signal, OS/driver hooks), dispatch tables for interpreters and state machines, and runtime-swappable strategies.In pure C++ prefer
std::functionor lambdas when state is needed. Only non-capturing lambdas convert to raw function pointers.