I have a function which expects parameters like this
void priqueue_init(priqueue_t *q, int(*comparer)(void *, void *))
I want it to be able to take arguments of any type.
In a separate file I first typedef
typedef int (*comp_funct)(job_t*, job_t*);
And the function I want to pass...
int fcfs_funct1(job_t* a, job_t* b)
{
int temp1 = a->arrival_time;
int temp2 = b->arrival_time;
return (temp1 - temp2);
}
The call to priqueue_init:
priqueue_init(pri_q, choose_comparator(sched_scheme));
And finally, my choose_comparator function:
comp_funct choose_comparator(scheme_t scheme)
{
if (sched_scheme == FCFS)
return fcfs_funct1;
return NULL;
}
I error on my call to priqueue_init.
libscheduler/libscheduler.c: In function ‘add_to_priq’:
libscheduler/libscheduler.c:125:3: error: passing argument 2 of ‘priqueue_init’ from incompatible pointer type [-Werror]
In file included from libscheduler/libscheduler.c:5:0:
libscheduler/../libpriqueue/libpriqueue.h:25:8: note: expected ‘int (*)(void *, void *)’ but argument is of type ‘comp_funct’
Where am I getting hung up? The file where priqueue_init is defined doesn't know about the type job_t. I thought going with void arguments was the way to go.