Jump Tables via Function Pointer Arrays in C/C++

来源:互联网 发布:光晕守护者和人工智能 编辑:程序博客网 时间:2024/05/26 02:54

by Nigel Jones


=================================================================================================================

Jump tables, also called branch tables, are an efficient means of handling similar events in software. Here's a look at the use of arrays of function pointers in C/C++ as jump tables.

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Examination of assembly language code that has been crafted by an expert will usually reveal extensive use of function "branch tables." Branch tables (a.k.a., jump tables) are used because they offer a unique blend of compactness and execution speed, particularly on microprocessors that support indexed addressing. When one examines typical C/C++ code, however, the branch table (i.e., an array of funtion pointers) is a much rarer beast. The purpose of this article is to examine why branch tables are not used by C/C++ programmers and to make the case for their extensive use. Real world examples of their use are included.

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


更多请参考阅读: http://www.barrgroup.com/Embedded-Systems/How-To/C-Function-Pointers

..............................................................................................................................................................................................................................................................





原创粉丝点击