Machine-translated by Google. Questions are authored in English.
Top

Discussion

The commonest reason for introducing a function pointer into firmware is to

  • A.allow a function to be placed in RAM rather than flash
  • B.guarantee that a call is inlined by the compiler
  • C.dispatch through a table of handlers
  • D.reduce the stack usage of a deep call chain

Answer: C

A state machine indexing an array of function pointers, or a driver registering a callback, is the natural use. The cost is that the call cannot be inlined and that an uninitialised pointer jumps somewhere arbitrary, which is why such tables are usually const.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.