This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Is it possible to have a computed jump in C?

Is it possible to have a computed jump in C?
Maybe a jumptable with hundereds of entries.

Don't want a switch case structure because every decision brings a time penalty.

:-)

Parents Reply Children
  • Most C compilers (and their optimizers) will implement switches as either a series of tests or a jump table depending on density of labels, number of labels, and so on.

    Ideally, an embedded compiler would have a pragma to let you force the implementation when you care. Sometimes, you want the constant-time execution of a jump table. Sometimes you might even prefer to priority-order your cases so that the earlier ones do execute first.

    You can, of course, always manually implement an if-then-else series, or else a table of function pointers, as desired.

  • Just wondering:

    With an ARM, is it likely that a jump table would be more or less code efficient than an array of function pointers?