An array of function pointers.
Joe English
english at panarea.usc.edu
Thu Sep 22 09:55:06 AEST 1988
In article <414 at ucrmath.UUCP> jantypas at ucrmath.UUCP (John Antypas) writes:
>We'd like to set up something like a vector table.
>If the vector table has a NULL in a spot, then the interpreter will use its
>internal routines instead of faster device specific code. As an example:
>
>vectors[] = { dev_line(),
> dev_box(),
> dev_circle(),
> dev_arc(),
> dev_text()
> }
>
>[...] ... when I
>try to copy function addresses, the compiler complains. How do I get the
>address of a funciton and put it into an array for calling later?
This works, (and it's an excellent way to set up a device driver, I
might add.) The only problem with the initialization is that you're
using function _call_ syntax, which can't be evaluated at compile
time. If you declare the functions (int dev_line(), dev_box(),...;)
beforehand, you can write:
int (*vectors)()[] = { dev_line,
dev_box,
...
}
_without_ parentheses; this evaluates to the address of the function,
which can be initialized, instead of a function call.
/|/| Joe English
-----< | | ARPA: english%lipari at oberon.usc.edu
O \|\|
More information about the Comp.lang.c
mailing list