This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Array of function pointers

I have a constant array of function pointers in code space and I an trying to declare a pointer variable to point to this array and then assign the array address to the pointer variable.

The C51 compiler gives an error 213 for the assignment.

Is there anything obviously wrong with what I am trying to do.

extern const void (code * code ArrayOfFunc[])();

void (code * code * xdata ptrArrayOfFunc[])();

main() {
ptrArrayOfFunc = ArrayOfFunc;
}

Thanks

Parents
  • In "normal" 'C', you need parenetheses in a function pointer declaration:

    int (*fun)(void);
    since, without the parentheses,
    int *fun(void);
    declares a function returning a pointer to int (K&R Chapter 5)

    This is complicated somewhat with Keil's memory-space specifiers (code, xdata, etc), so I'm not quite sure where the parentheses should go.

    Is the error 213 the very first error you get? C51 tends to report this error on every single line containing an array if there has been any preceding error in the compilation!

    BTW: is there any particular reason why you need to add this extra level of indirection?

    BTW2: I trust you have read-up on all the Gotchas! with function pointers in C51:
    http://www.keil.com/support/docs/210.htm
    Application Note 129

Reply
  • In "normal" 'C', you need parenetheses in a function pointer declaration:

    int (*fun)(void);
    since, without the parentheses,
    int *fun(void);
    declares a function returning a pointer to int (K&R Chapter 5)

    This is complicated somewhat with Keil's memory-space specifiers (code, xdata, etc), so I'm not quite sure where the parentheses should go.

    Is the error 213 the very first error you get? C51 tends to report this error on every single line containing an array if there has been any preceding error in the compilation!

    BTW: is there any particular reason why you need to add this extra level of indirection?

    BTW2: I trust you have read-up on all the Gotchas! with function pointers in C51:
    http://www.keil.com/support/docs/210.htm
    Application Note 129

Children
  • Hi Andrew,

    It's been a long week and I am sure that most of us stumble into a pointer trap at some time. I am not usually that bad with multiple indirection.

    The error 213 was the only error that popped up with the simple example.

    There is a reason for the level of indirection. I need to plug in 2 different display drivers into an application but not let the application worry about which type it is.

    One is an in-built LCD graphic panel connect to a processor port, the other an external display device with a VT100 type serial interface. Only 1 display can be active.