declaration
one basic type + zero or more derived types
basic type
char
, signed char
, unsigned char
, short
, unsigned short
, int
, unsigned int
, long
, unsigned long
, float
, double
, void
, struct tag
, union tag
, enum tag
, long long
, unsigned long long
, long double
derived types
*
: pointer to … - always on the left side
[]
: array of … - always on the left side
()
: function returning … - always on the left side
operator precedence
The []
and ()
have higher precedence than *
.
the rule to read declaration
There is a “right-left” rule. I think the rule is based on the precedence.
C pointer to array/array of pointers disambiguation also mentioned “go right when you can, go left when you must”.
find error in declaration
Since we can read complex declaration by applying the rule mentioned before, we also can find error in declaration with the knowledge of what is legal in C.
Some illegal declarations,
|
|
char *(*(**foo[][8])())[]
foo is array of array of 8 pointer to pointer to function returning pointer to array of pointer to char.
summary
- The key is the “right-left” rule.
- Be aware of what is legal in C.
- 数组指针,指针数组。。。Well, the Chinese description is really ambiguous.