In the header file I have the following line:
typedef int comparator(int* left, int* right);
But when I tried to write a function definition for it like so:
int comparator (int* left, int* right){
if(left<right) {
return 1;
} else if(right>left) {
return -1;
} else {
return 0;
}
}
The error I get is:
file.c:10: error: ‘comparator’ redeclared as different kind of symbol
The function must be typedef’ed because later on in the header file it is used in a method prototype like so:
struct bst_node** search(struct bst_node** root, comparator compare, void* data);
So how is this method constructed?
in your header file you should just have
your aren’t declaring a type, but just declaring a function.
you could declare a function pointer type called comparator…
but you wouldn’t then make a function called comparator. you just need to make a function with the same signature
then call
Also, I got a feeling you don’t want to be passing int* but actual int, or in your function you don’t want to be comparing the pointers, but comparing the values of what each int is pointing to, like
but possibly you are wanting to compare the memory locations where the ints are stored.
also your comparisons are the same
is the same as
so maybe you want