C/C++ casting issue?
Heh, well it won't win any beauty contests, but glad to see you got it working
LOl!
No it won't but it works and is optimal - thats what I wanted :-)))
Your help much appreciated!
Cheers
No it won't but it works and is optimal - thats what I wanted :-)))
Your help much appreciated!
Cheers
You don't need to explicitly store the address of a function pointer in your table - it's already a pointer 
I believe this might be a cleaner description for your function table:
You don't need to define the table as static and/or const but I like to be clear regarding the intentions of the code. Most likely you are not accessing the table outside the source file (static) or modifying the table during runtime (const).
Here's a test case showing how to call functions from your function table:
... and here's the definitions you'll need if you would like to compile the example yourself:
Have fun playing around with function tables - they can be a blast. Just make sure you actually need them first! Just like every solution shouldn't be inheritance in C++, neither should every solution in C be function tables. I quickly skimmed through this article that I found through Google and it looks like a good discussion of function tables.

I believe this might be a cleaner description for your function table:
Code:
static const HIT_FUNC hit_Blast[MAX_NUM_TYPES]=
{
no_hit,
wall_hit
};You don't need to define the table as static and/or const but I like to be clear regarding the intentions of the code. Most likely you are not accessing the table outside the source file (static) or modifying the table during runtime (const).
Here's a test case showing how to call functions from your function table:
Code:
static void test (void)
{
hit_Blast[0] ("one", "two");
hit_Blast[1] ("three", "four");
}... and here's the definitions you'll need if you would like to compile the example yourself:
Code:
typedef const char OBJECT_DEF;
typedef void (*HIT_FUNC) (OBJECT_DEF* ob1, OBJECT_DEF* ob2);
static void no_hit (OBJECT_DEF* ob1, OBJECT_DEF* ob2)
{
printf ("%s no hit %s\n", ob1, ob2);
}
static void wall_hit (OBJECT_DEF* ob1, OBJECT_DEF* ob2)
{
printf ("%s wall hit %s\n", ob1, ob2);
}
#define MAX_NUM_TYPES 2Have fun playing around with function tables - they can be a blast. Just make sure you actually need them first! Just like every solution shouldn't be inheritance in C++, neither should every solution in C be function tables. I quickly skimmed through this article that I found through Google and it looks like a good discussion of function tables.
The Monkey Hustle - Now available on the App Store!
Cheers man, thanks!

