Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!think!harvard!seismo!brl-adm!brl-smoke!smoke!dan@BBN-PROPHET.ARPA From: dan@BBN-PROPHET.ARPA Newsgroups: net.lang.c Subject: Re: Array of pointers to functions Message-ID: <2450@brl-smoke.ARPA> Date: Mon, 7-Apr-86 16:29:29 EST Article-I.D.: brl-smok.2450 Posted: Mon Apr 7 16:29:29 1986 Date-Received: Thu, 10-Apr-86 00:43:18 EST Sender: news@brl-smoke.ARPA Lines: 46 Re array of pointers to functions: the way I think of it is that C declarations must be read "from the inside out". Start with the identifier itself, and work your way out from the tightest-binding declaration operator to the loosest. The first declaration operator you hit gives you the fundamental type of the object. So, given a declaration containing ... (*x) ... No matter what is surrounding the "(*x)", x is a pointer. Always. Never an array, function, etc., though what it points to may involve these. On the other hand, given ... (x[5]) ... X is definitely an array of 5 (somethings). Maybe pointers, ints, etc. So, to construct an array of pointers, you say (x[]) to get the array, and add the '*' next: (*(x[])) Now it's an array of pointers. What do they point to? Functions: ( (*(x[])) () ) Now all you need to do is specify what the functions return: int ( (*(x[])) () ) And you're done. However, you've left behind a pretty confusing declaration. C typedefs are the perfect way to make things like this easy to understand: typedef int FUNC(); typedef FUNC * FUNC_PTR; FUNC_PTR x[]; Now it's quite clear that x is an array of function pointers. I usually use some variation on this when I have to construct such arrays; it's a lot clearer, even to people like me who have been using C for years. Hope this helps. Dan Franklin