1

I found the following C program these lines and don't know what they mean and do:

    int (*less)(void *m, size_t a, size_t b);
    int (*less)(void *m, size_t a, size_t b);
    void (*swap)(void *m, size_t a, size_t b);

and what are they equivalent to?

Martin Turjak
  • 20,896
  • 5
  • 56
  • 76
tudoricc
  • 709
  • 1
  • 12
  • 31

2 Answers2

1

The declarations are for function pointers, designed to point to functions with different signatures.

int (*less)(void *m, size_t a, size_t b);

This one is a function pointer called 'less', which is to be used with a function which takes a parameter list of (void *m, size_t a, size_t b), and return int. You could point this function pointer at a function like this:

int foo(void *m, size_t a, size_t b)
{
    return 0;
}

The second one is the same. The third one is this:

void (*swap)(void *m, size_t a, size_t b);

This one is a function pointer called 'swap', which is to be used with a function which takes a parameter list of (void *m, size_t a, size_t b), and return void. You could point this function pointer at a function like this:

void foo(void *m, size_t a, size_t b)
{
    return;
}

This website is handy for decoding these kinds of declarations.

Baldrick
  • 11,712
  • 2
  • 31
  • 35
0

They describe pointers to functions. See another SO question about this here

Community
  • 1
  • 1
ArtemB
  • 3,496
  • 17
  • 18