Array of pointers to functions

Wayne Throop throopw at dg_rtp.UUCP
Sat Apr 12 06:32:40 AEST 1986


AAAAUUUUGGGGHHHH!!!!

> Yesterday I asked which was right:
>     "int (*foo[SIZE])()" or "int ((*foo)())[];"
> The solution I got was to look at declarations from the inside out; thus
>      int foo                       - An integer
>      int *foo                      - A pointer to an integer
>      int (*foo)[]                  - An array of pointers to integers
>      int ((*foo)[])()              - An array of pointers to functions
>                                      returning integers.

Puh*LEEZE* try to be a little more careful, folks.  It is probable that
the error in the above is a typo, but typo or not, it spreads
misinformation.  The general principle of declaring from the inside out
is correct as stated above, but the last two examples are *INCORRECT*.

In particular, (*foo)[] is a pointer to an array, not an array of
pointers.  Read it from the inside out folks... pointer operation first,
then array, hence "pointer to array".  Similarly for the last example.
It is a pointer to an array of functions returning int, which isn't even
legal in C.

If the last example had been typechecked before posting, it would have
been obvious that it was bogus... lint barfs all over it, saying:

        array of functions is illegal

In addition, a local typechecker gives a somewhat more verbose
admonition, like so:

        arrays cannot contain this type
              (:FUNCTION_RETURNING (:INT))

As I've said before, puh*LEEZE* be more careful, and (where possible)
*TYPECHECK* *POSTED* *EXAMPLES* (with lint at least, and maybe more if
you've got more).
-- 
Wayne Throop at Data General, RTP, NC
<the-known-world>!mcnc!rti-sel!dg_rtp!throopw



More information about the Comp.lang.c mailing list