Function int (* cmp) (void *, void *)

0

I know that it compares pointers and returns an integer that determines whether one is smaller than another, in the order sense. But when I use it in main() , it is giving some error. Can you help me?

    
asked by anonymous 29.06.2016 / 16:04

1 answer

1

The question does not give much detail, but this is the signature of a function that will be received by the parameter of the function dllInsertAfterSpec() .

This is an anonymous function. That is, it is a pointer to a code somewhere. This pointer is stored in some variable (or can pass straight as an argument). You can pass any function, written in any language, as long as it has the signature to return an integer and pass as argument to it two generic pointers. Obviously the code is expected to use these arguments in a comparison and return a number that indicates how it worked. Just looking at the documentation to know exactly how to write this function. A hypothetical example:

int FuncaoASerUsada(void *lhs, void *rhs) {
    unsigned int a = *((unsigned int*)lhs);
    unsigned int b = *((unsigned int*)rhs);
    return (b - a);
}
dllInsertAfterSpec(l, data, key, FuncaoASerUsada);

A example of using pointers to functions can be found in this question . You have more example in this one .

Useful question to understand better .

    
30.06.2016 / 15:13