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
  • 38,251
  • 9
  • 74
  • 91
1

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

haccks
  • 100,941
  • 24
  • 163
  • 252
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
  • 168,892
  • 12
  • 149
  • 276
nvoigt
  • 68,786
  • 25
  • 88
  • 134
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,777
  • 1
  • 10
  • 2