This is the mail archive of the c++-embedded@sourceware.cygnus.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: static function tables


Ken wrote:
> 
> What's the right way to do static tables containing function pointers in
> C++?
> 
> I have an embedded C app that parses a command from a host and looks it
> up in a group of tables. Each table represents an array of related
> commands. It contains an 8-byte char[] of the command, a parameter
> count, some flags, and a pointer to the function that handles that
> command. There are several such tables, linked in based on what feature
> set a given app will have.
> 
> When I move this app to C++, what's a reasonable OOP-ish way of handling
> these tables?

How about not using function pointers? Maybe use a table of command
objects instead? You could have a base command class then
derive more specific commands from these. The table would
contain pointers to command objects so you could treat all
the command the same but the behaviour would be that of the
derived class. Not sure if this fits your app but if it works
it is better than using function pointers. Function pointers
should be very rare in a c++ app.


------------------------------------------------------------------
      tmh@possibility.com   http://www.possibility.com/Tmh
   Desperate measures require the invention of desperate times. 
      -- Todd Hoff


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]