See
http://cdecl.org/[
^]: You enter your C-declaration and get "prosa" description of the declaration.
To read a C-declaration, do the following iterative rule:
- start at the entity
name
--> "declare name as " - if there is a
(
... )
to the right of the current location
--> "function (...) returning " - else if there is a
[
... ]
to the right of the current location
--> "array ... of " - else if there is
const
or volatile
to the left of the current location
--> "const " or "volatile " - else if there is
*
to the left of the current location
--> "pointer to " - else if the current location is nested in
(
... )
--> nothing - else if there is a
typename
to the left of the current location
--> "typename " - if all "eaten up"
--> done - else goto 2)
E.g.
type *pointername; --> 1,5,9,7,8
type *arrayname[SIZE]; --> 1,3,9,5,9,7,8
type (*arrayname[SIZE])(typeofarguments); --> 1,3,9,5,9,6,9,2,7,8
I.e. the above mentioned declarations translate into:
- declare pointername as | pointer to | type
- declare arrayname as | array SIZE of | pointer to | type
- declare arrayname as | array SIZE of | pointer to | function (typeofarguments) returning | type
Cheers
Andi
PS: C++ is a bit more complex with respect to references (e.g.
&
and
&&
goes with
*
), unnamed entities (e.g. in alias declaration which are analogous to typedefs: find the location where the starting name would be located), deducing if a name is type or a class member name, pointer to member, etc. The good thing is, one can easily extend the above rules to fit C++ declaration (or to reject them so they are expressions). E.g. x*y; is a declaration if x is a type, otherwise, it is an expression where the result of the operator call is not stored.