C syntax
edhall%rand-unix at sri-unix.UUCP
edhall%rand-unix at sri-unix.UUCP
Fri Aug 19 17:01:00 AEST 1983
Try:
static void (*p[N])();
In general, remember that modifiers to a given type (that is,
(), *, and []) are parsed right-to-left, successively modifying
the base type of the item. Parentheses can change this order.
Thus, the above declaration parses:
[N] Array of N
* Pointers to
() Functions returning
void type `void',
static storage class `static'.
Another toughie would be an array of pointers to functions returning
strings:
char *(p[N])();
With a bit of practice, though, creating data types in C is about
as simple as any other language. Some complain that C is `backwards'
from languages like PASCAL. This is because the C declaration was
designed to be an example of the use of the object declared; thus,
using the second declaration for `p', above, the value of `x' in:
x = *(p[n])();
is of type `char'. This `declaration by example' is more of a feature
than a obstacle.
-Ed Hall
Rand Corporation
More information about the Comp.unix.wizards
mailing list