How do you implement this functionality?

I'm studying AI and robot control, and at the same time trying to improve my C programming skills. I am working on implementing an A* search algorithm, which I have done before, but I want to implement in a specific way. What I want to implement, is an abstract A* search algorithm that a user can include in their program and pass to it the implementations for the various functions/structs that A* needs. Like the heuristic and a node struct.

It could be implemented by #including "somefile.c" in the A* file, and mandating the user name their file "somefile.c", which would include the implementation of all the functions and types that A* expects. But, can it be done such that the A* file doesn't need to include the user's file?

I'm working in straight C and have been playing around with structs with function pointers, but I'm not having much success in figuring out how to make this work.

My A* file basically looks like this right now...

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>

typedef struct _aStar{
  void (*h)(Node* n); /* Heuristic Function */
}aStar;

void search(aStar* userImpl);
void search(aStar* userImpl)
{
  return;
}


The user should be able to include this file, then put function pointers into the aStar struct and pass it to the search function, which will perform the search using the user implemented functions. The "Node" struct should also be user defined.


Is there a name for what I am trying to implement? And, can anyone point me towards standard methods for implementing this kind of functionality?

Thanks.
Last edited on
Topic archived. No new replies allowed.