tags:

views:

174

answers:

4

This function definition is found here. :

static void (*resolve_memcpy (void)) (void)
{
    return my_memcpy; // we'll just always select this routine
}

I don't understand what it means. help? :D

+5  A: 

resolve_memcpy is a function taking no arguments and returning a pointer to a function taking no arguments and returning void.

EDIT: Here's a link where you can read more about this kind of syntax: http://unixwiz.net/techtips/reading-cdecl.html

usta
So it says in the link :D. I don't understand the syntax though. Can you be more elaborate?
nakiya
@nakiya: See my edit :)
usta
Thanks for the link.
nakiya
+2  A: 

One can use cdecl to find:

declare resolve_memcpy as static function (void) returning pointer to function (void) returning void

ArunSaha
Thanks for the link
nakiya
A: 

It basically returns a function pointer, which (presumably) you're supposed to use instead of memcpy.

// memcpy(...)
resolve_memcpy()(...) // Use this instead.
Peter Alexander
+2  A: 

Here's my standard method for reading hairy declarations: start with the leftmost identifier and work your way out, remembering that absent any explicit grouping () and [] bind before *:

              resolve_memcpy               -- resolve_memcpy
              resolve_memcpy(void)         --  is a function taking no arguments
             *resolve_memcpy(void)         --  and returning a pointer
            (*resolve_memcpy(void)) (void) --   to a function taking no arguments
       void (*resolve_memcpy(void)) (void) --   and returning void
static void (*resolve_memcpy(void)) (void) -- and is not exported to the linker

So the return value of the resolve_memcpy function is a pointer to another function:

void (*fptr)(void) = resolve_memcpy();
fptr(); // or (*fptr)(), if you want to be explicit

If you want to drive your coworkers insane, you could write

resolve_memcpy()(); 

which will execute the function whose pointer is returned by resolve_memcpy.

John Bode
+1. Nice 1. Thanks.
nakiya