4 ms·
In C, the statement “type declarator;” is an assertion that “declarator” has the type “type”. In other words, if you read “declarator” as an expression (more or
by evincarofautumn 10y ago
In C, the statement “type declarator;” is an assertion that “declarator” has the type “type”. In other words, if you read “declarator” as an expression (more or less), then it should have the type “type”. So here:
foo (*baz(bing, boff (*bratz)(biff)))(buff);
“foo” is the type, and the rest is the declarator. Then you just break it down according to the usual precedence rules:
baz(…)
“baz” is a function…
baz(bing, …)
…which takes a “bing”, and…
*bratz
…a pointer (arbitrarily named “bratz”)…
(*bratz)(biff)
…to a function which takes a “biff”…
boff(*bratz)(biff)
…and returns a “boff”…
*baz(…)
…and “baz” returns a pointer…
(*baz(…))(buff)
…to a function taking a “buff”…
foo (*baz(…))(buff)
…and returning a “foo”.
With typedefs for function pointer types:
typedef boff (*bratz_t)(biff);
typedef foo (*baz_ret_t)(buff);
baz_ret_t baz(bing, bratz_t);
Or for function types:
typedef boff bratz_t(biff);
typedef foo baz_ret_t(buff);
baz_ret_t *baz(bing, bratz_t *);