C "function pointer" typedef without asterisk?

Viewed 527

Possible Duplicate:
what does this typedef mean? a function prototype ?

Today I came across this syntax

typedef double (d2d)(double);

cdecl tells me it's a function returning a double (as opposed to a pointer to a function returning a double). So let's see how it works:

#include <stdio.h>

typedef double (d2d)(double);
//typedef double (*d2d)(double); // the "usual" way

double twice(double x)
{
    return x * 2.0;
}

double apply(d2d f, double x)
{
    return f(x);
}


int main()
{
    printf("%f\n", apply(twice, 2.0)); // Prints 4.0000
    return 0;
}

Surprisingly, GCC 4.2.1 compiled it without problems. I'm just curious to know what are the subtle differences between this and the "usual" way to typedef a function pointer?

0 Answers
Related