user302520
user302520

Reputation:

Complicated Declaration

How do we interpret the following declaration:

char (*(*f())[])();

How shall one develop a handy technique to read such complicated or even more complicated declarations in C. If you use a quick trick, please share.

Upvotes: 3

Views: 213

Answers (2)

Alexandre C.
Alexandre C.

Reputation: 56976

There is indeed a not-so-well-known trick. Pretend that f is a variable name, and that *, () and [] are operations you can do on it. Use the precedence rules of C operators to wit that:

f

can be applied

f()

and then dereferenced

*f()

and then subscripted

(*f())[]

and then dereferenced

*(*f())[]

and then applied

(*(*f())[])()

to give a char

char (*(*f())[])()

so f is a function returning a pointer to an array of pointers to functions returning char.

Upvotes: 2

Foo Bah
Foo Bah

Reputation: 26271

http://www.antlr.org/wiki/display/CS652/How+To+Read+C+Declarations gives a good tutorial.

Upvotes: 0

Related Questions