Skip to main content
GameDev.net gamedev.net
🔒 Locked

Array of function pointers?

Started by trysil Dec 5, 2001 at 3:46 AM 3 replies 300+ views
Original Post
trysil
trysil
Has anyone done this? How? Is it even possible? /Trysil "A witty and slightly sarcastic quote from an unkown source" -- The generic SIG /trysil
"A witty and slightly sarcastic quote from an unkown source"-- The generic SIG/trysil
RabidOcelot
RabidOcelot
    
#include <stdio.h>


void SayHello ()
{
printf ("Hello.\n");
}


int main (void)
{
void (*pFunctions [10]) ();

pFunctions[0] = SayHello;

pFunctions[0] ();

return 1;
}


Game: The Adventure (tm).
-------------------------


Edited by - RabidOcelot on December 5, 2001 5:28:23 AM
siaspete
siaspete
Yeah I''ve done it.

In my application it turned out to be a bit of a wasted effort though. I was writing a 6502 processor emulator, and I thought it would be a lot faster to use an array of function pointers instead of a huge switch statement.

Turns out Visual C++ turns huge switch statements into jump tables.

- Pete
Tok
Tok
You can use a function pointer (type void*) as you would any other pointer variable. RabidOcelot couldn''t have put it better (even told you how to do it)
siaspete: I wrote a command parser for a text adventure using a ternary search tree with a function pointer at each "found" node. Talk about a wasted effort- 11mos followed by segmentation faults I couldn''t trace, followed by hard drive failure where I lost everything. :~(
-Tok.

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Feel free to email me HERE
*Howdy Kids, Do /YOU/ know what time it is? It''s tangent time* -Baldor the Bold
--------------------------~The Feature Creep of the Family~
RolandofGilead
RolandofGilead
from siaspete:
"Turns out Visual C++ turns huge switch statements into jump tables"

Does any other compiler do that, such as the free borland
compiler which I use?

Is there a speed difference between an array of function
pointers and a switch statement?
I''m making either an interpreter or a custom script for
my game(I can''t tell the difference between the two).

Create.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.