Daniel Rudy <.0123456789> wrote:
> How does one call a pointer? Basically, what I would like to do is
> have an array of pointers so that a value of a variable in a struct will
> act as an index to the array, which contains the addresses of routines.
> How does one do this in C? Can it be done? I'm still new to C, so
> some of the code below will not be valid...Like the pointer type.
> #include <stdio.h>
> pointer array[3];
Make that
int ( * array[ 3 ] )( void );
That way you get an array with 3 elements, with its element being pointers
to int returning functions that take no arguments (but you should make
that a global variable unless you really need
> int x;
> int routine1()
> {
> printf("This is routine 1\n");
> return(0);
> }
> int routine2()
> {
> printf("This is routine 2\n");
> return(0);
> }
> int routine3()
> {
> printf("This is routine 3\n");
> return(0);
> }
> int main()
> {
> array[0] = addressof(routine1);
Much too complicated, make that
array[0] = routine1;
etc.
> array[1] = addressof(routine2);
> array[2] = addressof(routine3);
> x = 2;
> call(array[x]);
And use here just
array[2]( );
> return(0);
> }
Regards, Jens
--
\ Jens Thoms Toerring ___
\__________________________
http://www.toerring.de