![]() |
Pointer to array of pointers to functions
Ok I have an array of pointers to functions that return int and take
void like: int (*funcsP[])(void) = {func_a, func_b}; Now I want to create a pointer to that array and I can't figure out the correct "incantation" :) Any help would be appreciated. Ace |
Re: Pointer to array of pointers to functions
merlin100 <aceman500@gmail.com> writes:
> Ok I have an array of pointers to functions that return int and take > void like: > > int (*funcsP[])(void) = {func_a, func_b}; > > Now I want to create a pointer to that array and I can't figure out > the correct "incantation" :) > > Any help would be appreciated. Are you sure you want a pointer to the array? Usually it's more useful to have a pointer to an element of the array; by incrementing that pointer, you can step through the array. For a pointer to the entire array: int (*(*arr_ptr)[2])(void) = &funcsP; For a pointer to an element of the array: int (*(*elem_ptr))(void) = funcsP; The "cdecl" command is very useful for this kind of thing: % cdecl Type `help' or `?' for help cdecl> explain int (*funcsP[])(void) declare funcsP as array of pointer to function (void) returning int cdecl> declare arr_ptr as pointer to array of pointer to function (void) returning int Warning: Unsupported in C -- 'Pointer to array of unspecified dimension' (maybe you mean "pointer to object") int (*(*arr_ptr)[])(void ) cdecl> declare arr_ptr as pointer to array 2 of pointer to function (void) returning int int (*(*arr_ptr)[2])(void ) cdecl> declare elem_ptr as pointer to pointer to function (void) returning int int (**elem_ptr)(void ) cdecl> -- Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst> Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" |
Re: Pointer to array of pointers to functions
You are a genius Keith, a pointer to the first element of the array is
what I needed and it works and thanks for the cdecl tip it's great I love it! > For a pointer to an element of the array: > > * * int (*(*elem_ptr))(void) = funcsP; Thats the ticket. I don't know why I did not try that.. Thanks again! Ace |
Re: Pointer to array of pointers to functions
On Thu, 24 Mar 2011 16:08:34 -0400, merlin100 <aceman500@gmail.com> wrote:
> Ok I have an array of pointers to functions that return int and take > void like: > > int (*funcsP[])(void) = {func_a, func_b}; > > Now I want to create a pointer to that array and I can't figure out > the correct "incantation" :) Rather than giving yourself headaches trying to deal with C's messy syntax for function pointers, consider using a typedef: typedef int (*funcp)(void); /* funcp is ptr to func(void) returning int */ funcp funcsP[] = {func_a, func_b}; funcp *funcp_ptr = funcsP; /* Or equivalently, funcp *funcp_ptr = &funcsP[0]; */ -- Morris Keesan -- mkeesan@post.harvard.edu |
| All times are GMT. The time now is 10:40 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.