Hi, I have written a simple 8051-application using uVision2 V2.37. I have defined a function which expects a pointer to a function which is then saved in an array of function pointers: int registerFunction( void (*Fct) (void) ) { .... functArray[i] = Fct; .... } calling the function "(*functArray[i])()" fails. As far as I have heard when passing any kind of pointers as parameters the keyowrd "xdata" have to be used in the declaration and the definition of the functions: int foo(int* xdata var); I have tried to use "xdata" in my function declaration, but the compiler did not allow that. Does anybody know how to pass a function pointer as a parameter ?? Best regards hammoud
calling the function "(*functArray[i])()" fails Fails --- how? the keyowrd "xdata" have to be used That's quite probably misinformation, or wrongly interpreted by you. Care referencing the source of this statement? All that said, the most important answer you need is that this is not at all a good technique to use on a '51. Function pointers wreak havoc with call tree analysis, causing all kinds of nasty problems. See the sections about function pointers in the manual
The following application note coveres everything you must know about function pointers and the C51 Compiler. http://www.keil.com/appnotes/docs/apnt_129.asp Jon
Be not deceived. The title read "tips and techniques for using them effectively in your 8051" there is no such thing. Imp0lementing function pointers in a '51 is an acrobatic circus act. ONCE MORE: the '51 is not a PC. Erik
First, make sure your 'functArray[]' is correctly defined as function pointers. Second, replace
(*functArray[i])()
(*(functArray+i))()