I have following typedef declarations in c but confused how I read these declarations.
typedef char *pc; /* pc is pointer to char */
typedef pc fpc(); /* fpc is function returning pointer to char */
typedef fpc *pfpc;
typedef pfpc fpfpc();
typedef fpfpc *pfpfpc;
pfpfpc a[N];
Now for me first two statement is easy to read but really confused after that.
Is there any way to solve(read) such equations?
Good so far. Note that the last typedef can also be written as
Next,
declares
pfpcas a pointer tofpc. Since we know thatfpcis a function returning a pointer tochar, thenpfpcmust be a pointer to a function returning pointer tochar, orNext we have
This time,
fpfpcis a function returningpfpc. Since we know thatpfpcis a pointer to a function returning pointer tochar,fpfpcmust be a function returning a pointer to a function returning pointer tochar, orNext, we have
which declares
pfpfpcas a pointer tofpfpc. Since we knowfpfpcis a function returning a pointer to a function returning pointer tochar, pfpfpc must be a pointer to a function returning a pointer to a function returning a pointer tochar, orFinally, we have an an N-element array of
pfpfpcSince we know
pfpfpcis a pointer to a function returning pointers to functions returning pointers tochar, thenamust be an N-element array of pointers to functions returning pointers to functions returning pointers tochar:The main rule to remember for reading and writing hairy declarations is that
[]and()have higher precedence than*, soand the whole thing is broken down as
Going the other way, we have
The last step isn’t terribly intuitive, I’ll admit.