1

What does

  int(*compare)(void* argu1, void*argu2);

mean? I have never seen something like this, it is in my binary search tree chapter and is it in the BST strucutre:

typdef struct{
             int counter; 
             int(*compare)(void* argu1, void*argu2);
             NODE* root;
             }BST; 
user3211189
  • 69
  • 2
  • 7

4 Answers4

2

This is a variable named compare which is a pointer to a function. The function returns an int and receives two void * parameters.

Function pointers are frequently used for providing a way to generically compare two values of a type that some other function (such as a sorting or ordering routine) does not understand; the caller provides a function to do the comparison on the generic function's behalf.

mah
  • 39,056
  • 9
  • 76
  • 93
1

It means compare is a pointer to a function having its both parameter of type void * and having return type int.

haccks
  • 104,019
  • 25
  • 176
  • 264
1
int(*compare)(void* argu1, void*argu2);

This is a variable declaration. The variable is a function pointer and its name is "compare". It can point to any function that returns an int and takes two void pointers.

Eric Postpischil
  • 195,579
  • 13
  • 168
  • 312
nvoigt
  • 75,013
  • 26
  • 93
  • 142
0

The code declares a variable named "compare". This variable is a function pointer type, meaning you can assign a function name to this variable, and later invoke this function just like making a regular function call. For further reading, you may refer to early binding vs. late binding.

user3307545
  • 2,847
  • 1
  • 11
  • 2