Array of pointers to functions
cjl at iuvax.UUCP
cjl at iuvax.UUCP
Tue Apr 15 03:14:00 AEST 1986
> I'm confused. How do you specify an array of pointers to functions? Do
> you do it:
> int (*foo[])();
> or do you do it:
> int ((*foo)())[];
If C enforces postfix notations for all its declarations, the world will
be more peaceful. Two of its declarators use postfix notation ( [] and () ),
while pointer uses prefix notation ( * ). Confusion about declarator precedence
will disappear IF we CHANGE the syntax of pointer declarator to a postfix
notation. So when we speak "an array of pointers to functions", we
can write down immediately as "int foo [] * ()". To face the reality
in the C world, we translate the above back into " (* (foo [])) () ".
(Parentheses are used here to avoid the precedence problem.)
Remembering the rule that postfix declarators has higher priority than
prefix declarators, we can save some of the parentheses as
" (* foo []) () ".
C.J.Lo
UUCP : ...!iuvax!cjl
ARPA : cjl at Indiana@CSNet-Relay
More information about the Comp.lang.c
mailing list