Jump Tables via Function Pointer Arrays in C/C++
2012-09-16 09:16
330 查看
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
..............................................................................................................................................................................................................................................................
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
..............................................................................................................................................................................................................................................................
相关文章推荐
- Fast implementation/approximation of pow() function in C/C++
- [C++] inline function
- Exporting a function in a DLL using Microsoft Visual C++ 6.0
- The two-dimensional pointer operation in C++
- (NOT CLEAR)Question 44: What member function of std::fstream could a C++ developer invoke in order to change the target output f
- Can we use function on left side of an expression in C and C++?
- Virtual method and base-type pointer make polymorphism in C++
- 实用程序软件包(关于使用静态函数报错问题“Static function declared but not defined in C+++ "eh.h is only for C++!"报错问题)
- Fast Integer Log2 function in C/C++
- [C++]Partly Specialize member function in Class Templates
- Fast C++ Delegate: Boost.Function 'drop-in' replacement and multicast
- Define the input/output port name for the Inlined C++ S-function block in Matlab Simulink
- C/C++ Basics--function pointer
- [c++] Inline Function
- The pointer in C++ /CLI
- Functors: Function Objects in C++
- Effective C++ Item 17 Store newed objects in smart pointer in standalone statements
- Functors: Function Objects in C++
- C++ AMP: Staging Arrays in C++ AMP
- C++ 11: lexical closure in lambda function, example 1