How can I make sense of this C type declaration?

c, declaration

Solution

This answer is brought to you by the ability to use the Spiral Rule. Being able to understand a complex expression by starting at the unknown element and reading around it (resolving things in the parenthesis first). A very useful skill when reading code.

        bar                                            - bar
        bar()                                          - is a function
        bar(int, )                                     - which takes an int...
        bar(int, (*)())                                - and a function pointer
        bar(int, double(*)())                          - which returns a double
        bar(int, double(*)(double, ))                  - and takes a double...
        bar(int, double(*)(double, double[]))          - and an array of doubles
      (*bar(int, double(*)(double, double[])))         - and returns a pointer
      (*bar(int, double(*)(double, double[])))()       - to a function
      (*bar(int, double(*)(double, double[])))(double) - taking a double
double(*bar(int, double(*)(double, double[])))(double) - which returns a double

That was the hard way... There are of course sites that make this easier, the cdecl site for example; but it's good to be able to read code even when you can't get to the internet.

Problem

``` double (*bar(int, double(*)(double,double[])))(double); ``` While reviewing a lecture slide, I found an exercise left to the student: In plain English, what is the type of `bar` in this C declaration? Please help walk me through this. I don't even know where to begin, except that something is ultimately returning a double.

Original source